php - How to change the "while" loop to retrieve only 3 top records from MySQL database -
i set query select * from, used while loop print out retrieved records , works fine. need print out top 3 of records, there way change while loop make work way.
any on appreciated, thx
while($row = $alerts_query->fetch_object()){ echo "<div class='panel'> <div class='panel-heading'> <h3 class='panel-title'>" . $row->ticket_title . " <a href='clientpanel.php?tab=dashboard=" . $row->ticketid . "' aria-hidden='true' type='button' class='close pull-right'>x</a></h3> </div> <div class='panel-body'>" . $row->ticket_description . " <br /> <br /> <span style='color: #999'>reported: " . $row->ticket_date . "</span> </div> </div>"; }
do not limit in while
loop (though, it's possible). change sql instead:
select * yourtable
append:
select * yourtable limit 3
if reason should in php (not advised in situation):
$i = 0; while($row = $alerts_query->fetch_object() , $i<3) { $i++; // ... }
Comments
Post a Comment