Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Scroll de Noticias

Estas en el tema de Scroll de Noticias en el foro de Mysql en Foros del Web. Hola: Tengo una base de datos donde voy almecenando noticias, que se muestran en el apartado creado al respecto. Mi problema viene en que en ...
  #1 (permalink)  
Antiguo 18/08/2011, 11:41
 
Fecha de Ingreso: abril-2008
Mensajes: 348
Antigüedad: 16 años
Puntos: 1
Scroll de Noticias

Hola:

Tengo una base de datos donde voy almecenando noticias, que se muestran en el apartado creado al respecto.

Mi problema viene en que en el index quiere mostrar las ultimas que se han publicado en un scroll.

He ojeado, di con algun tipo marquee o scrpit, pero ninguna de las soluciones que vi es lo que buscaba.

Lo mas parecido seria algo parecido a este ejemplo:
http://www.dynamicdrive.com/dynamicindex2/crosstick.htm

pero habria que hacerlo que "enlazara automaticamente" con las ultimas noticias publicadas.

Un saludo
  #2 (permalink)  
Antiguo 18/08/2011, 16:43
 
Fecha de Ingreso: julio-2011
Mensajes: 220
Antigüedad: 12 años, 9 meses
Puntos: 72
Respuesta: Scroll de Noticias

El código que se halla en la página que mencionas se puede acupar para lo que quieres junto con PHP, esto seria creando el contenido del array de javascript con la información extraida de la base de datos, asi cada vez que se abriera tú página index se mostrarian las últimas noticias.
  #3 (permalink)  
Antiguo 21/08/2011, 04:54
 
Fecha de Ingreso: abril-2008
Mensajes: 348
Antigüedad: 16 años
Puntos: 1
Respuesta: Scroll de Noticias

Vamos a ver, avanzamos.

Pero viene el problema grande:

Este es el codigo del script:

Código Javascript:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <style type="text/css">
  7.  
  8. /*Example CSS for the two demo scrollers*/
  9.  
  10. #pscroller1{
  11. width: 200px;
  12. height: 100px;
  13. border: 1px solid black;
  14. padding: 5px;
  15. background-color: lightyellow;
  16. }
  17.  
  18.  
  19. .someclass{ //class to apply to your scroller(s) if desired
  20. }
  21.  
  22. </style>
  23.  
  24. <script type="text/javascript">
  25.  
  26. /*Example message arrays for the two demo scrollers*/
  27.  
  28. var pausecontent=new Array()
  29. pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
  30. pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
  31. pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'
  32.  
  33.  
  34. </script>
  35.  
  36. <script type="text/javascript">
  37.  
  38. /***********************************************
  39. * Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
  40. * This notice MUST stay intact for legal use
  41. * Visit http://www.dynamicdrive.com/ for this script and 100s more.
  42. ***********************************************/
  43.  
  44. function pausescroller(content, divId, divClass, delay){
  45. this.content=content //message array content
  46. this.tickerid=divId //ID of ticker div to display information
  47. this.delay=delay //Delay between msg change, in miliseconds.
  48. this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
  49. this.hiddendivpointer=1 //index of message array for hidden div
  50. document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
  51. var scrollerinstance=this
  52. if (window.addEventListener) //run onload in DOM2 browsers
  53. window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
  54. else if (window.attachEvent) //run onload in IE5.5+
  55. window.attachEvent("onload", function(){scrollerinstance.initialize()})
  56. else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
  57. setTimeout(function(){scrollerinstance.initialize()}, 500)
  58. }
  59.  
  60. // -------------------------------------------------------------------
  61. // initialize()- Initialize scroller method.
  62. // -Get div objects, set initial positions, start up down animation
  63. // -------------------------------------------------------------------
  64.  
  65. pausescroller.prototype.initialize=function(){
  66. this.tickerdiv=document.getElementById(this.tickerid)
  67. this.visiblediv=document.getElementById(this.tickerid+"1")
  68. this.hiddendiv=document.getElementById(this.tickerid+"2")
  69. this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
  70. //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
  71. this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
  72. this.getinline(this.visiblediv, this.hiddendiv)
  73. this.hiddendiv.style.visibility="visible"
  74. var scrollerinstance=this
  75. document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
  76. document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
  77. if (window.attachEvent) //Clean up loose references in IE
  78. window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
  79. setTimeout(function(){scrollerinstance.animateup()}, this.delay)
  80. }
  81.  
  82.  
  83. // -------------------------------------------------------------------
  84. // animateup()- Move the two inner divs of the scroller up and in sync
  85. // -------------------------------------------------------------------
  86.  
  87. pausescroller.prototype.animateup=function(){
  88. var scrollerinstance=this
  89. if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
  90. this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
  91. this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
  92. setTimeout(function(){scrollerinstance.animateup()}, 50)
  93. }
  94. else{
  95. this.getinline(this.hiddendiv, this.visiblediv)
  96. this.swapdivs()
  97. setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
  98. }
  99. }
  100.  
  101. // -------------------------------------------------------------------
  102. // swapdivs()- Swap between which is the visible and which is the hidden div
  103. // -------------------------------------------------------------------
  104.  
  105. pausescroller.prototype.swapdivs=function(){
  106. var tempcontainer=this.visiblediv
  107. this.visiblediv=this.hiddendiv
  108. this.hiddendiv=tempcontainer
  109. }
  110.  
  111. pausescroller.prototype.getinline=function(div1, div2){
  112. div1.style.top=this.visibledivtop+"px"
  113. div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
  114. }
  115.  
  116. // -------------------------------------------------------------------
  117. // setmessage()- Populate the hidden div with the next message before it's visible
  118. // -------------------------------------------------------------------
  119.  
  120. pausescroller.prototype.setmessage=function(){
  121. var scrollerinstance=this
  122. if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
  123. setTimeout(function(){scrollerinstance.setmessage()}, 100)
  124. else{
  125. var i=this.hiddendivpointer
  126. var ceiling=this.content.length
  127. this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
  128. this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
  129. this.animateup()
  130. }
  131. }
  132.  
  133. pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
  134. if (tickerobj.currentStyle)
  135. return tickerobj.currentStyle["paddingTop"]
  136. else if (window.getComputedStyle) //if DOM2
  137. return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
  138. else
  139. return 0
  140. }
  141.  
  142. </script>
  143. </head>
  144.  
  145. <body>
  146. <script type="text/javascript">
  147.  
  148. //new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)
  149.  
  150. new pausescroller(pausecontent, "pscroller1", "someclass", 1000)
  151.  
  152.  
  153. </script>
  154. </body>
  155. </html>


Y este es el codigo de la base de datos:
Código PHP:
Ver original
  1. <?
  2. //Conexion con la base
  3. mysql_connect( "localhost", "usuario", "contraseña");//Ejecutamos la sentencia SQL
  4. $result=mysql_db_query("base","SELECT * FROM tabla");
  5. //Mostramos los registros
  6.  
  7. echo '<Marquee Behavior="Scroll" Direction="Up" Height="140" ScrollAmount="3"
  8.  
  9. ScrollDelay="100" onMouseOver="this.stop()" onMouseOut="this.start()">';
  10. echo '<table>';
  11. while ($row=mysql_fetch_array($result))
  12. {
  13. echo"<tr>
  14. <td>".$row["titulo"]."</td>
  15. </tr>";
  16. }//fin del while
  17. echo"</table></marquee>";
  18. ?>


Pero lo siento, no se como "enlazarlos", alguna idea de como hacerlo?

Un saludo y gracias
  #4 (permalink)  
Antiguo 22/08/2011, 18:50
 
Fecha de Ingreso: julio-2011
Mensajes: 220
Antigüedad: 12 años, 9 meses
Puntos: 72
Respuesta: Scroll de Noticias

Este código funciona bien.

Cita:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">

/*Example CSS for the two demo scrollers*/

#pscroller1{
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
background-color: lightyellow;
}


.someclass{ //class to apply to your scroller(s) if desired
}

</style>

<?php
$conexion= mysql_connect("localhost", "usuario", "contraseña");
mysql_select_db("base", $conexion);
$result= mysql_query("select * from tabla", $conexion);

echo "<script type=text/javascript>\n";

/*Example message arrays for the two demo scrollers*/

echo "var pausecontent=new Array()\n";

$contador= 0;

while($row=mysql_fetch_array($result))
{
echo "pausecontent[$contador]='".$row['titulo']."'\n";
$contador++;
}


echo "</script>\n";

mysql_close($conexion);

?>

<script type="text/javascript">

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize( )}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.ticker id)
this.visiblediv=document.getElementById(this.ticke rid+"1")
this.hiddendiv=document.getElementById(this.ticker id+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpa dding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.w idth=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover =function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout= function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover= scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup() }, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibled ivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv .style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.s tyle.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup() }, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage( )}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeig ht, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage( )}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

</script>
</head>

<body>
<script type="text/javascript">

//new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)

new pausescroller(pausecontent, "pscroller1", "someclass", 1000)


</script>
</body>
</html>
Como se aprecia todo lo que se necesita hacer es conectarse a la base de datos y recuperar la información de la tabla adecuada, luego con esta información escribir el array javascript que es el que se muestra en el scroll.

Cita:
<?php
$conexion= mysql_connect("localhost", "usuario", "contraseña");
mysql_select_db("base", $conexion);
$result= mysql_query("select * from tabla", $conexion);

echo "<script type=text/javascript>\n";

/*Example message arrays for the two demo scrollers*/

echo "var pausecontent=new Array()\n";

$contador= 0;

while($row=mysql_fetch_array($result))
{
echo "pausecontent[$contador]='".$row['titulo']."'\n";
$contador++;
}


echo "</script>\n";

mysql_close($conexion);

?>
En este caso solo se mostrara el texto con el título de la noticia, si se desea que este sea un enlace hacia una página que muestra la noticia completa esto se debe realizar dentro del bucle while que escribe el Array. Por ejemplo:

Cita:
while($row=mysql_fetch_array($result))
{
echo "pausecontent[$contador]='<a href=\"ruta_de_la_pagina\">".$row['titulo']."</a>'\n";
$contador++;
}
Asi mismo si se quiere incluir un pequeño resumen de cada noticia, que se tenga en la tabla de la base de datos, se debe realizar en este bloque.
  #5 (permalink)  
Antiguo 22/08/2011, 23:25
 
Fecha de Ingreso: abril-2008
Mensajes: 348
Antigüedad: 16 años
Puntos: 1
Respuesta: Scroll de Noticias

hola:

Lo primero es agradecerte tu tiempo y participacion.

No me funciona, cambie los datos de conexcion ( usuario, contraseña, base y tabla) pero no va.

Alguna idea?

Un saludo y gracias de nuevo
  #6 (permalink)  
Antiguo 23/08/2011, 05:35
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: Scroll de Noticias

El problema de conexión entre una página y una base de datos programada con PHP u otro lenguaje, no es problema de este foro, y prácticamente no lo es de MySQL en sí. Es un asunto de programación en esos lenguajes.
El servidor de MySQL sólo necesita que los parámetros de la conexión sean correctos, pero todo el resto es del lenguaje usado.
Este post habría tenido posiblemente soluciones más rápido y con mejor participación si en lugar de ponerlo en este foro, lo hubieses puesto en donde corresponde: Foro de PHP, Java, Ajax o JSP, tu sabrás.

Espera que lo pasen al foro correcto, yo ya lo notifiqué.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: scroll
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:30.