mysql - How would i execute a php while loop a specific number of times? -
im using bootstrap , main index page in php, have been trying dynamically display data database want display 5 of rows in database table.
echo '<ul class="sort" id="rank_ul">'; $res = mysql_query("select * ifc order votes desc"); while($row=mysql_fetch_assoc($res)) {?> <li id="li<?php echo $row['id']?>"> <div class="tut-img"> <img src="<?php echo $row['img']?>" width="50" height="70" alt="<?php echo $row['title']?>" /> <div class="drag-label"></div> </div> <div class="title"> <a href="<?php echo $row['url']?>" target="_blank" title=""><?php echo $row['title']?></a> </div> </li> <?php }?> </ul>
essentially code creating many list items there rows in data, make stop creating list items @ specific number of times, issue had wanted keep in descending order , switching while loop loop or do-while didnt create list items.
the simplest (and best) way add limit
clause query so:
$res = mysql_query("select * ifc order votes desc limit 5");
as side note, highly recommend using either pdo or mysqli instead of old, deprecated mysql extension.
Comments
Post a Comment