Page 1 of 1

Paging Question

Posted: Sun Jun 28, 2009 2:31 am
by abie
I can't figure out where I'm going wrong. I am trying to setup paging to show 5 rows per page. But it's not working out correctly. Any thoughts on why?

Code: Select all

 
include("dbinfo.inc.php");
include("header.inc");
 
//how many rows to show per page
$rowsPerPage = 5;
 
//show first page by default
$pageNum = 1;
 
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
 
// counting the offset
$offset = ($pageNum - 1 * $rowsPerPage);
 
mysql_connect("$hostname",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query= "SELECT * FROM scores order by ID DESC";
     "LIMIT $offset, $rowsPerPage";
 
$result=mysql_query($query);
 
//print the pages
while($row = mysql_fetch_array($result))
{
    echo $row['user'] .  ' bowled a' . $row['score'] . ' on ' . $row['date'] . '<br>';
}
 
 

Re: Paging Question

Posted: Sun Jun 28, 2009 7:27 am
by Darhazer
In my honest opinion

Code: Select all

$offset = ($pageNum - 1 * $rowsPerPage)
Should be

Code: Select all

$offset = ($pageNum - 1) * $rowsPerPage

Re: Paging Question

Posted: Sun Jun 28, 2009 5:32 pm
by abie
Didn't really do anything to help...still same problem

Code: Select all

<?
include("dbinfo.inc.php");
include("header.inc");
 
//how many rows to show per page
$rowsPerPage = 5;
 
//show first page by default
$pageNum = 1;
 
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
 
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
 
mysql_connect("$hostname",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query= "SELECT * FROM scores order by ID DESC";
     "LIMIT $offset, $rowsPerPage";
 
$result=mysql_query($query);
 
//print the pages
while($row = mysql_fetch_array($result))
{
    echo $row['user'] .  ' bowled a' . $row['score'] . ' on ' . $row['date'] . '<br>';
}
 
?>
 

Re: Paging Question

Posted: Sun Jun 28, 2009 10:57 pm
by McInfo

Code: Select all

$query= "SELECT * FROM scores order by ID DESC"; // This semicolon should be a dot and there should be a space between DESC and LIMIT
     "LIMIT $offset, $rowsPerPage";
Edit: This post was recovered from search engine cache.