Problem with mysql query in paging

Posted by jasmine on Stack Overflow See other posts from Stack Overflow or by jasmine
Published on 2010-06-05T17:27:20Z Indexed on 2010/06/05 17:32 UTC
Read the original article Hit count: 156

Filed under:
|

I have a very simple paging and mysql query. Im not sure that my query is right:

$perPage =4; 

$page= (isset($GET['page']) && is_numeric($GET['page'])) ? $_GET['page'] : 1;
$start = ($page * $perPage ) - $perPage ;
if (is_numeric($_GET['cID'])){$cid = $_GET['cID'];}
$totalCount = sprintf("SELECT COUNT(*) as 'Total' FROM content WHERE catID = %d", $cid ) ;
$count = mysql_query($totalCount);
$rowCount = mysql_fetch_array($count);

$sql = sprintf("SELECT id, title, abstract, content_image FROM content WHERE catID = %d ORDER BY id DESC LIMIT %d, %d", $cid, $start, $perPage );
$query = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($query)){
  echo $row['id'].' : '. $row['title'] .'<br>';
}

with

/categories.php?cID=1&page=2 and /categories.php?cID=1&page=1

The output is:

95 : titlev
94 : titlex
93 : titlec
92 : titleb

and not changed. What is wrong in my query? Thanks in advance

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql-query