Limiting number of rows in a query
Posted: Mon Mar 20, 2006 2:53 pm
HI all,
This is what I have so far, and it works...
What I need to do is only List the top 3... How do I do this, please???
I have tried creating a counter in the while statement but that didn't work (or I did not do it correctly)...
Something like:
Thank you in advance for any help...
Clinton
This is what I have so far, and it works...
Code: Select all
class clsNextShows { // List the next 3 shows for the right-hand menu
function fctNext3Shows () {
require('Connections/damsel.php');
mysql_select_db($database_damsel, $damsel);
$query_rstNextShows = "SELECT * FROM mtblshows WHERE dteStartDate > CURRENT_DATE ORDER BY dteStartDate ASC";
$rstNextShows = mysql_query($query_rstNextShows, $damsel) or die(mysql_error());
$totalRows_rstNextShows = mysql_num_rows($rstNextShows);
while ($arrNextShows = mysql_fetch_array($rstNextShows)) {
$txtSN = $arrNextShows ['txtShowName'];
$lnkLink = $arrNextShows ['txtWebsite'];
echo '<a href="'.$lnkLink.'">'.$txtSN.'</a><br>';
}
mysql_free_result($rstNextShows);
}
} // End clsNextShowsI have tried creating a counter in the while statement but that didn't work (or I did not do it correctly)...
Something like:
Code: Select all
$counter = 1;
while (($arrNextShows = mysql_fetch_array($rstNextShows)) && ($counter <= 3)) {
$txtSN = $arrNextShows ['txtShowName'];
$lnkLink = $arrNextShows ['txtWebsite'];
echo '<a href="'.$lnkLink.'">'.$txtSN.'</a><br>';
$counter++;
}Clinton