Forum Moderators: coopster

Message Too Old, No Replies

page pagination script.

not working

         

ski442

10:11 pm on Apr 12, 2007 (gmt 0)

10+ Year Member



Hi Guys.

I have this pagination script below, which i have taken from treads that i have found with this forum, but cannot get it to work.

This seems to be a big problem in general as i have read 100's of threads.

If you guys would cast your eyes over this as my head is spinning.

It might show in the script that i am still learning, which i am, only been doing php for 2 months now. A little guidance is what i need or do i need a new script.

Thanks guys in advance.
ski442

<?php
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}

$query = @mysql_query("SELECT * FROM products ") or die(mysql_error());
$query_data = @mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 10;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM products $limit";
$result;


if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}

echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // Display the text of all the products in a paragraph

while ($row = @mysql_fetch_row($result)) {

echo "<p>" . $row['stockcode'] . "</p>";
echo "<p>" . $row['catprice'] . "</p>";
echo "<p>" . $row['price'] . "</p>";
echo "<p>" . $row['instock'] . "</p>";

}if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}// if
?>

darrenG

11:14 pm on Apr 12, 2007 (gmt 0)

10+ Year Member



Im tired, and have been working all day, so might be wrong!

But instead of:

$query = @mysql_query("SELECT * FROM products ") or die(mysql_error());
$query_data = @mysql_fetch_row($result);
$numrows = $query_data[0];

Try:

$query = @mysql_query("SELECT count(*) FROM products") or die(mysql_error());
$query_data = @mysql_fetch_row($result);
$numrows = $query_data[0];

There are some other little tweaks required I _think_, but its gone midnight and Im shattered!