Jump to content

select 3 latest mysql results to be shown in turn?


fallreg

Recommended Posts

This is the data table I have: id date content

 

How do I select three latest results from mysql to get the following effect?

 

    <body>
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="64">Latest News:</td>
        <td width="321"><script>
    var marqueeContent=new Array();
    marqueeContent[0]='<a href="#" target="_blank">bla bla bla</a>';
    marqueeContent[1]='<a href="#" target="_blank">hua hua hua</a>';
    marqueeContent[2]='<a href="#" target="_blank">lalalalalalala</a>';
    var marqueeInterval=new Array(); 
    var marqueeId=0;
    var marqueeDelay=4000;
    var marqueeHeight=15;
    function initMarquee() {
     var str=marqueeContent[0];
     document.write('<div id=marqueeBox style="overflow:hidden;height:'+marqueeHeight+'px" onmouseover="clearInterval(marqueeInterval[0])" onmouseout="marqueeInterval[0]=setInterval(\'startMarquee()\',marqueeDelay)"><div>'+str+'</div></div>');
     marqueeId++;
     marqueeInterval[0]=setInterval("startMarquee()",marqueeDelay);
     }
    function startMarquee() {
     var str=marqueeContent[marqueeId];
      marqueeId++;
     if(marqueeId>=marqueeContent.length) marqueeId=0;
     if(marqueeBox.childNodes.length==1) {
      var nextLine=document.createElement('DIV');
      nextLine.innerHTML=str;
      marqueeBox.appendChild(nextLine);
      }
     else {
      marqueeBox.childNodes[0].innerHTML=str;
      marqueeBox.appendChild(marqueeBox.childNodes[0]);
      marqueeBox.scrollTop=0;
      }
     clearInterval(marqueeInterval[1]);
     marqueeInterval[1]=setInterval("scrollMarquee()",10);
     }
    function scrollMarquee() {
     marqueeBox.scrollTop++;
     if(marqueeBox.scrollTop%marqueeHeight==marqueeHeight){
      clearInterval(marqueeInterval[1]);
      }
     }
    initMarquee();
    </script></td>
      </tr>
    </table>
    </body>

 

The links # are to be replaced with "content" in the mysql table

Amazing that you posted a mysql question with so much as a mysql query.

 

I've tried:

$count = mysql_query("SELECT COUNT(id) FROM my_posts");

 

Then:

$q1 = mysql_query("SELECT * FROM my_posts ORDER BY id DESC LIMIT 1");  // to be the first result

 

And:

$q2 = mysql_query("SELECT * FROM my_posts WHERE id<$count LIMIT 1");  //to be the second result

 

but this cannot be executed..

Amazing that you posted a mysql question with so much as a mysql query.

 

I've tried:

$count = mysql_query("SELECT COUNT(id) FROM my_posts");

 

Then:

$q1 = mysql_query("SELECT * FROM my_posts ORDER BY id DESC LIMIT 1");  // to be the first result

 

And:

$q2 = mysql_query("SELECT * FROM my_posts WHERE id<$count LIMIT 1");  //to be the second result

 

but this cannot be executed..

mysql_query returns a resource, using its return value like an integer is clearly incorrect and will never work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.