this script is so much like David's script. like so (included as a user-submitted input on the lecture on the same topic):
<?
$connection = mysql_connect("localhost", "root", "vis") or die ("Couldn't connect to database");
$db = mysql_select_db("StoreDB", $connection) or die ("Couldn't select DB");
$limit = 5;
$sqlcount= "SELECT whatever FROM whatever ORDER BY whatever";
$sql_countresult = mysql_query($sqlcount, $connection) or die ("Couldn't execute query");
$totalrows = mysql_num_rows($sql_countresult);
if(empty($page)){
$page = 1;
}
$limitvalue1 = $page*$limit-($limit);
$sql = "SELECT whatever FROM whatever ORDER BY whatever LIMIT $limitvalue1, $limit";
$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query");
while ($row = mysql_fetch_array($sql_result)){
data here
}
echo "<BR>";
if($page != 1) {
$pageprev= $page - 1;
echo "<A HREF=\"products.php?page=$pageprev\"> PREV </A>"; // if page is not equal to one, prev goes to $page - 1
}
else {
echo "<A HREF=\"products.php?page=$page\"> PREV </A>"; // Otherwise, PREV reloads the page
}
$numofpages = $totalrows/$limit;
for($i= 1; $i < $numofpages; $i++) {
echo "<A HREF=\"products.php?page=$i\"> $i </A>"; //make number navigation
}
if($totalrows%$limit != 0) {
echo "<A HREF=\"products.php?page=$i\"> $i </A>"; ////if there is a remainder, add another page
}
if(($totalrows-($limit$page)) > 0){
$pagenext = $page + 1;
echo "<A HREF=\"products.php?page=$pagenext\"> NEXT </A>"; // if the totalrows - $limit $page is > 0 (meaning there is a remainder), leave the next button.
}
mysql_free_result($sql_result);
mysql_close($connection);
?>
i've been having the same problem as Bill. diference is, when i click on my next or prev button, the script outputs all the contents in my database.
how do i apply your advice on this?
thanks..
manny