Forum Moderators: coopster
list($totalrows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM $table " . $where_query));
in the above code $totalrows shows as 6 while
$query = "SELECT * FROM $table " . $where_query ." ORDER BY ". $orderby
only shows 5 entries (i removed the lImit) making me belive that i am doing something wrong in displaying the table enteries it self.
i suspect it has to something with my while statment when i am printing the database entries
========================
$page = $_GET["page"];
if (($page<0) ¦¦ ($page=="")) $page=0;
$epp = 2; /* entries per page */
$l1 = $epp*($page);
$l2 = $epp;
list($totalrows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM $table " . $where_query));
$query = "SELECT * FROM $table " . $where_query ." ORDER BY ". $orderby." LIMIT $l1, $l2";
$result = mysql_query($query) or die("SQL Error: " . mysql_error() );
if(mysql_fetch_row($result)=="0")
{
print("<tr><td colspan='7' align='center'>Sorry no results found. Please try your search again.</td></tr>");
}
else{
print("<tr><td colspan='7' align='center'>");
print($totalrows." Results Found.<br/>");
if($page!=0){
print("<a href='$PHP_SELF?page=".($page-1)."&search=".$search."&searchfield="
.$searchfield."&bookfor=".$bookfor."&orderby=".$orderby."&country=".$country."
&school=".$school."&iprefer=".$iprefer."' alt='Previous Page' title='Previous Page'>[ Previous ]</a>");
}
$totalpages =(int)( $totalrows / $epp);
print(" Page # ".($page+1)." ");
if(($page+1)!=$totalpages && ($totalpages!=0)){
print("<a href='$PHP_SELF?page=".($page+1)."&search=".$search."&searchfield="
.$searchfield."&bookfor=".$bookfor."&orderby=".$orderby."&country=".$country."
&school=".$school."&iprefer=".$iprefer."' alt='Next Page' title='Next Page'>[ Next ]</a>");
}
while($row = mysql_fetch_row($result)){
trimmed irrelevant code to fix sidescroll
}
mysql_close();
}
[edited by: coopster at 1:38 pm (utc) on July 30, 2004]
$result = mysql_query($query) or die("SQL Error: " . mysql_error() );
if(mysql_fetch_row($result)=="0") { whileloop, it is going to start with row #2 of the result set.
while ($row = mysql_fetch_row($result)) {
Make sense? You have a couple of options. You could either use mysql_data_seek() [php.net] to move the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. Or, better yet, use mysql_num_rows [php.net] to get the number of rows in the result set to test in your
ifstatement as this will not advance the internal pointer of the result set on you.
$result = mysql_query($query) or die("SQL Error: " . mysql_error() );
if(mysql_num_rows($result)=="0") {