fallreg Posted January 17, 2012 Share Posted January 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/ Share on other sites More sharing options...
AyKay47 Posted January 17, 2012 Share Posted January 17, 2012 order by primary_index desc limit 3 Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/#findComment-1308416 Share on other sites More sharing options...
fenway Posted January 17, 2012 Share Posted January 17, 2012 Amazing that you posted a mysql question with so much as a mysql query. Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/#findComment-1308441 Share on other sites More sharing options...
fallreg Posted January 17, 2012 Author Share Posted January 17, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/#findComment-1308451 Share on other sites More sharing options...
fallreg Posted January 17, 2012 Author Share Posted January 17, 2012 I have figure out the solution by myself. Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/#findComment-1308477 Share on other sites More sharing options...
AyKay47 Posted January 17, 2012 Share Posted January 17, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255192-select-3-latest-mysql-results-to-be-shown-in-turn/#findComment-1308529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.