Jump to content

Limit Table Rows – mysql_fetch_array()


Cyberdave

Recommended Posts

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.