I have a simple pagination script on my movie_categories.php page (see below). I have added the following to the page: $cat_id = intval($_GET['cat_id']); PHP: Now, when someone clicks on, say, movie_categories.php?cat_id=horror, they will land on movie_categories.php and all of the horror movies will be presented. Everything works fine, except, when there is more than 1 page of results, the other pages don't work. For example, if there are 7 movies, and movies 1 to 5 are presented on Page 1, movies 6 and 7 are not presented on Page 2. Page 2 just says 'None'. Can anyone see why this is happening? movie_categories.php: <?php $conn = mysql_connect('localhost', 'root') or trigger_error("SQL", E_USER_ERROR); mysql_select_db('hidden', $conn) or trigger_error("SQL", E_USER_ERROR); $cat_id = intval($_GET['cat_id']); $query = "SELECT COUNT(*) FROM tbl_movies WHERE cat_id='$cat_id'"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // end else $rows_per_page = 5; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // end if if ($pageno < 1) { $pageno = 1; } // end if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $select = "SELECT . . . WHERE cat_id='$cat_id' $limit"; $select_results = mysql_query($select, $conn) or trigger_error("SQL", E_USER_ERROR); if (mysql_num_rows($select_results) >= 1) { if ($pageno == 1) { echo " "; } else { echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=1'>First</a> "; $prevpage = $pageno-1; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>Prev</a> "; } // end else echo " Page $pageno of $lastpage "; if ($pageno == $lastpage) { echo " "; } else { $nextpage = $pageno+1; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$nextpage?'>Next</a> "; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>Last</a> "; } // end else while($row = mysql_fetch_assoc($select_results)) { echo "Result . . ."; } // end while } // end first if else { echo "None"; } ?> PHP: It's like the script doesn't support URLs with variables in them. When I land on Page 1, the URL in the browser address bar looks like this: movie_categories.php?id=horror. But when I click to Page 2, it looks like this: movie_categories.php?pageno=2. Anyone understand what's going on?
correct me if I'm wrong here, but don't you need to put the cat_id back into the paging urls as well?
Hi, Shallowink. That's the first thing I tried (i.e., <a href='{$_SERVER['PHP_SELF']}?cat_id=$cat_id?pageno=1'>First</a>), but it just kept showing Page 1's results on Page 2. Any other suggestions?
Well, you might have more than one problem. From the first lines of that code, it looks like cat_id is going to have to be passed. You might try echoing all of the relevant variables to debug it. That's how I would start to track down what's going on.
Ah, heck! I'm so retarded! Look at the way I done the URLs: <a href='{$_SERVER['PHP_SELF']}?cat_id=$cat_id?pageno=1'>First</a>. I put a question mark (?) between the two parameters instead of an ampersand (&). It should've been like this: <a href='{$_SERVER['PHP_SELF']}?cat_id=$cat_id&pageno=1'>First</a>. Sorry for wasting everyone's time. Shallowink, one rep point for you.
Dude, it didn't let me give you a rep point. I must have repped you recently for something else. I'll give you one later.
Hello, We are giving a free pagination script so take good care of it.. http://www.stylesofts.com/portal/pagingScript.php/ Regards, Stylesofts Developing Team