Cyberdave Posted October 25, 2011 Share Posted October 25, 2011 How can I limit the number of rows displayed by the code below? $display = ' <table class="fixt-res"> <thead> <tr> <th>Date</th> <th>Team</th> <th>Versus</th> <th>Time</th> <th>Venue</th> </tr> </thead> '; while($mrow = mysql_fetch_array($mresult)) { $display .= '<tr>'; $display .= '<td class="fixt-res">'.date('d/m/Y', strtotime($mrow['matchdate'])).'</td>'; $display .= '<td class="fixt-res">'; $sqlcode = "SELECT * FROM $tbl_grade WHERE `gradeID` = '".$mrow['grade']."' LIMIT 1"; $resultcode = mysql_query($sqlcode); $rowcode = mysql_fetch_array($resultcode); $display .= $rowcode['gradename']; $display .= '</td>'; $display .= '<td class="fixt-res">'; $sqlcode = "SELECT * FROM $tbl_team WHERE `teamID` = '".$mrow['team2']."' LIMIT 1"; $resultcode = mysql_query($sqlcode); $rowcode = mysql_fetch_array($resultcode); $display .= $rowcode['teamname']; $display .= '</td>'; if(date('H:i', strtotime($mrow['matchtime'])) == '00:00') $display .= '<td class="fixt-res"><acronym title="To Be Decided">TBD</acronym></td>'; if(date('H:i', strtotime($mrow['matchtime'])) != '00:00') $display .= '<td class="fixt-res">'.date('H:i', strtotime($mrow['matchtime'])).'</td>'; $display .= '<td class="fixt-res">'; $sqlcode = "SELECT * FROM $tbl_venue WHERE `venueID` = '".$mrow['matchvenue']."' LIMIT 1"; $resultcode = mysql_query($sqlcode); $rowcode = mysql_fetch_array($resultcode); $display .= $rowcode['venuename']; $display .= '</td>'; $display .= '</tr>'; } $display .= '</table>'; return $display; ?> </table> Link to comment https://forums.phpfreaks.com/topic/249812-limit-table-rows-%E2%80%93-mysql_fetch_array/ Share on other sites More sharing options...
requinix Posted October 25, 2011 Share Posted October 25, 2011 Add a LIMIT to whatever query produces $mresult. Link to comment https://forums.phpfreaks.com/topic/249812-limit-table-rows-%E2%80%93-mysql_fetch_array/#findComment-1282252 Share on other sites More sharing options...
jcbones Posted October 26, 2011 Share Posted October 26, 2011 To further clarify requinix, You limit the rows from a database with a LIMIT clause in the query. SELECT * FROM table LIMIT 10 <-returns first 10 rows. SELECT * FROM table LIMIT 10,10 <- starts rows at row 10, returns 10 rows. Link to comment https://forums.phpfreaks.com/topic/249812-limit-table-rows-%E2%80%93-mysql_fetch_array/#findComment-1282259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.