I need an advanced help.....Here is the code I have been working on it...Actually I got this code from a book named PHP & MySQL by Luke Welling..What a pitty that He didnt write anything about paging....
I put 12 elements in the BOOKS table and want to get 3 per page results as
Page 1 Page 2 ....... etc...
a d
b e
c f
I would like to be able to PAGE my results as it is done on this forum site (PhpBuilder)...
but when the HTTPis like that http://www.sungolds.com/chapter25/show_cat.php?catid=1&offset=3
I got no results but when it is like http://www.sungolds.com/chapter25/show_cat.php?catid=1&offset=0 I got something like
a
b
c
but when OFFSET =3,6,9 I got nothing just emptty
I guess all the problem is becacuse of catagorizaton
I need to use CATID for each catagory difers from 1 to 4......
for each catagory I can display the books under that catagory like
http://www.sungolds.com/chapter25/show_cat.php?catid=1
but when I want to display 3 result per page I need to use
http://www.sungolds.com/chapter25/show_cat.php?catid=1&offset=3
but this doesnt work
HELP MEEEEEEEEEEEE
I am out of my minddd for days and nightssssss
<?
include ('book_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();
$name = get_category_name($catid);
do_html_header($name);
// get the book info out from db
$book_array = get_books($catid);
function display_books($book_array)
{
global $limit,$offset,$count;
//display all books in the array passed in
if (!is_array($book_array))
{
echo "<br>No books currently available in this category<br>";
}
else
{
//create table
echo "<table width = \"100%\" border = 0>";
//create a table row for each book
$count=count($book_array);
echo $count+1;
$limit=3;
if (!$offset) $offset=0;
$numpage=intval($count/$limit);
if ($count%$limit) {
$numpage++; // add one page if remainder
}
for ($k=$offset;$k<=$limit-1;$k++)
{
$url = "show_book.php?isbn=".($book_array[$k]["isbn"]);
echo "<tr><td>";
if (@file_exists("images/".$book_array[$k]["isbn"].".jpg"))
{
$title = "<img src=\"images/".($book_array[$k]["isbn"]).".jpg\" border=0>";
do_html_url($url, $title);
}
else
{
echo " ";
}
echo "</td><td>";
$title = $book_array[$k]["title"]." by ".$book_array[$k]["author"];
do_html_url($url, $title);
echo "</td></tr>";
}
echo "</table>";
echo "<hr>";
if ($numpage>1) {
echo "
<TABLE CELLPADDING=0 BORDER=0 CELLSPACING=6 WIDTH=400>
<TR>
<TD ALIGN=RIGHT>";
if ($offset>=$limit) {
$newoff=$offset-$limit;
$url = "show_cat.php?catid=".($book_array[0]["catid"])."&offset=".$newoff;
$title="<-- PREV" ;
do_html_url($url, $title);
echo "</TD>";
} else {
echo "<-- PREV";
}
echo "<TD ALIGN=CENTER> ";
for ($i=1;$i<=$numpage;$i++) {
if ((($i-1)$limit)==$offset) {
print "$i ";
} else {
$newoff=($i-1)$limit;
$url = "show_cat.php?catid=".($book_array[0]["catid"])."&offset=".$newoff;
$title=$i ;
do_html_url($url, $title);
}
}
echo " </TD>
<TD ALIGN=LEFT>";
if ($offset!=$limit*($numpage-1)) {
$newoff=$offset+$limit;
$url = "show_cat.php?catid=".($book_array[0]["catid"])."&offset=".$newoff;
$title="NEXT-->" ;
do_html_url($url, $title);
echo "</TD>";
}else{
echo "NEXT--></TD>";
}
echo "</TR>
</TABLE>";
}
}
}
display_books($book_array);
// if logged in as admin, show add, delete book links
if(session_is_registered("admin_user"))
{
display_button("index.php", "continue", "Continue Shopping");
display_button("admin.php", "admin-menu", "Admin Menu");
display_button("edit_category_form.php?catid=$catid", "edit-category", "Edit Category");
}
else
display_button("index.php", "continue-shopping", "Continue Shopping");
do_html_footer();
?>