[thelist] php display 3x2

Howard Cheng howcheng at ix.netcom.com
Tue Dec 3 11:49:00 CST 2002


At 05:01 PM 12/3/2002 +0000, Andrew Maynes wrote:
>$sql = "SELECT ... FROM ... ORDER BY ... LIMIT " . ($page - 1 * 3) . ", 6";


Oops, I left out a set of parentheses. This should have been:

(($page - 1) * 3)

The LIMIT clause in MySQL takes two parameters, the starting record number
and the number of records to retrieve. So to get the first six, you want
"LIMIT 0,6". That's why you need to subtract 1 from your page number.

>// do the query
>$sql = "SELECT image, title FROM book_shop";
>$result = mysql_query($sql, $connect);
>
>// this query should produce only 6 records per page.
>
>$query_data = mysql_fetch_row($result);
>  $total_num_locn = $query_data[0];
>  if(!$total_num_locn) error_message('No Books Found!');
>  $page_num = $cur_page + 1;

This query will retrieve all records from the table, which isn't what you
need to calculate the total number of pages. As you have it,
$total_num_locn will get you the 'image' field of the first record. You
should select the count instead:

SELECT COUNT(*) FROM book_shop

HTH.

::::::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/
howcheng at ix dot netcom dot com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list