RedHat Posted May 9, 2012 Share Posted May 9, 2012 Hello mates, I'm newbie in PHP and I'm trying to make something here. I'm working on a script that allows me to write some comments (from admin panel) and display them on my index page. For now, the script is displaying me all comments that I'm writing, and I want to display just 5 let's say. Any solution for this? <tbody> <?php $scom=mysql_query("select * from comments order by date desc"); $num=mysql_num_rows($scom); if($num!=0) { while($randc=mysql_fetch_array($scom)) { echo' <tr> <td width="50" align="center" valign="top" bgcolor="#B5D2DC"><img src="images/500999.png" width="30" height="30" /></td> <td class="textmic"> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#B5D2DC"> <tr> <td class="textc"><u>'.$randc["date"].'</u></td> </tr> <tr> <td align="justify">'; $newtext = wordwrap($randc["comment"], 20, "\n", true); echo $newtext.'</td> </tr> <tr> <td> <hr width="100%" noshade="noshade" size="8" color="#B5D2DC" /> </td> </tr> </table> </td> </tr> '; } } ?> </tbody> Quote Link to comment https://forums.phpfreaks.com/topic/262321-php-display-elements/ Share on other sites More sharing options...
Jessica Posted May 9, 2012 Share Posted May 9, 2012 In your query, use LIMIT 5 Quote Link to comment https://forums.phpfreaks.com/topic/262321-php-display-elements/#findComment-1344326 Share on other sites More sharing options...
RedHat Posted May 9, 2012 Author Share Posted May 9, 2012 Well, when you are a newbie you are newbie That was the solution, thank you jesirose! LE: I will stay around here, as I see you have a nice forum here Quote Link to comment https://forums.phpfreaks.com/topic/262321-php-display-elements/#findComment-1344339 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.