473,735 Members | 5,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pagination Problem

I am having a problem with pagination, basically the problem is happening in
the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue
the increment and decrement operators aren't functioning or the $page
variable isnt working in that part of the code... Below is the link to the
working but broken page.. as well as the main part of my code... Hopefully
someone can explain why the operators arent working or maybe see what i am
overlooking.

LINK: http://movies.evilacid.com

Note: most pagination code will be between
########
//comment
CODE
#######

PHP Code:
=============== =============== ====
<?php

require ('config.php');

if (!function_exis ts('connect_to_ mysql')){

function connect_to_mysq l(){

global $db_location,$d b_username,$db_ password,$db_da tabas
e;

$conn =
mysql_connect(" $db_location"," $db_username"," $db_password");
if (!$conn) die("Error: " . mysql_error());
mysql_select_db ($db_database,$ conn) or die("Error: " .
mysql_error());

return;
}
}

if (!function_exis ts('error_messa ge')){

function error_message($ text){

echo"<p align='left' class='errortex t'><br><b><span
style='backgrou nd-color: #FF6666'>Error: </span></b><br>$text</p>";

return;

}

}
############### ############### ############### #####
############### ###############

function list_all($cat,$ sortby,$char,$p age,$pageprev){
global $title;
############### ############### #
// part of pagination code
$limit = 25;
if(!$page){
$page = 1;
}
############### ############### ##

$how_many = mysql_num_rows( mysql_query("SE LECT * FROM moviedb"));

echo "<table width=\"820\" border=\"0\" cellspacing=\"0 \"
cellpadding=\"0 \">";
echo "<tr><td><cente r><font size=\"6\">$tit le</font></center></td></tr>";
echo "<tr><td><cente r>Currently $how_many movies in
database</center></td></tr>";
echo "<tr><td><cente r><br>";
echo quick_links();
echo "</center></td></tr>";
echo "</table>\n";
echo "<table width=\"820\" border=\"1\" cellspacing=\"0 \"
cellpadding=\"0 \">";
echo "<tr>";
echo "<th width=\"35\" bgcolor=\"66ccf f\"></th>";
echo "<th width=\"400\" bgcolor=\"66ccf f\"><strong>< a
href=\"index.ph p?t=&sortby=tit le\">Movie Title</a> </strong></th>";
echo "<th width=\"260\" bgcolor=\"66ccf f\"><strong>< a
href=\"index.ph p?t=&sortby=rat ing\">Rating</a></strong></th>";
echo "<th width=\"125\" bgcolor=\"66ccf f\"><strong>< a
href=\"index.ph p?t=&sortby=cat \">Genre</a></strong></th>";
echo "</tr>";

connect_to_mysq l();

############### ############### ####
//pagination code
$limitvalue = $page * $limit - ($limit);
############### ############### ####
if ($sortby == "") {
$sql = mysql_query("SE LECT * FROM moviedb ORDER BY title ASC LIMIT
$limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "recent") {
$sql = mysql_query("SE LECT * FROM moviedb ORDER BY date DESC LIMIT
$limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "alpha") {
$sql = mysql_query("SE LECT * FROM moviedb WHERE alpha LIKE '$char' ORDER
BY title ASC LIMIT $limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb WHERE alpha LIKE
'$char'");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "genre") {
$sql = mysql_query("SE LECT * FROM moviedb WHERE cat LIKE '$cat' ORDER BY
title ASC LIMIT $limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb WHERE cat LIKE '$cat'");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "title") {
$sql = mysql_query("SE LECT * FROM moviedb ORDER BY title ASC LIMIT
$limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "rating") {
$sql = mysql_query("SE LECT * FROM moviedb ORDER BY rating DESC LIMIT
$limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb");
$totalrows = mysql_num_rows( $q_count);
}
elseif ($sortby == "cat") {
$sql = mysql_query("SE LECT * FROM moviedb ORDER BY cat ASC LIMIT
$limitvalue, $limit");
$q_count = mysql_query("SE LECT * FROM moviedb");
$totalrows = mysql_num_rows( $q_count);
}

$bgcolor = "#E0E0E0"; // light gray
$result = $sql;
$z = 1;
while($rs = mysql_fetch_arr ay($result)) {
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
$alpha = $rs['alpha'];
$title = $rs['title'];
$link = $rs['link'];
$rating = $rs['rating'];
$ratingf = format_rating($ rating);
$category = $rs['cat'];
$stars = get_stars($rati ng);

echo "<tr>";
echo "<td width=\"35\" bgcolor=\"$bgco lor\"><center>$ z</center></td>";
echo "<td width=\"400\" bgcolor=\"$bgco lor\"><a
href=\"$link\"> $title</a></td>";
echo "<td width=\"260\" bgcolor=\"$bgco lor\">$stars ($ratingf)</td>";
echo "<td width=\"125\"
bgcolor=\"$bgco lor\"><center>$ category</center></td>";
echo "</tr>\n";
$z++;
}
echo "</table>\n";
############### ############### ############### ##### #
//PAGINATION LINKS STARTS HERE
if($page != 1){
$pageprev = $page--;

echo("<a href=\"index.ph p?t=&page=$page prev\">PREV".$l imit."</a> ");
}else{
echo("PREV".$li mit." ");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"index.ph p?t=&page=$i\"> $i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"index.ph p?t=&page=$i\"> $i</a> ");
}
}

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page--;

echo("<a href=\"index.ph p?t=&page=$page next\">NEXT".$l imit."</a>");
}else{
echo("NEXT".$li mit);
}
############### ############### ############### #

return;

}

//was browse_by_cat()
function quick_links(){

print <<<EOF
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#1 11111" width="820" id="AutoNumber1 ">
<tr>
<td width="100">
<form action='$_SERVE R[PHP_SELF]' method='get' name="form">
<input type='hidden' name='t' value=''>
<input type='hidden' name='sortby' value='genre'>
<select name="cat" size="1" id="cat" onchange="this. form.submit();" >
<option value="" selected>Browse By Genre</option>
<option value="%">All Movies</option>
<option value="action"> Action</option>
<option value="adventur e">Adventure </option>
<option value="animatio n">Animation </option>
<option value="biograph y">Biography </option>
<option value="comedy"> Comedy</option>
<option value="crime">C rime</option>
<option value="document ary">Documentar y</option>
<option value="drama">D rama</option>
<option value="educatio nal">Educationa l</option>
<option value="family"> Family</option>
<option value="fantasy" >Fantasy</option>
<option value="horror"> Horror</option>
<option value="music">M usic</option>
<option value="musical" >Musical</option>
<option value="mystery" >Mystery</option>
<option value="romance" >Romance</option>
<option value="scifi">S ci-Fi</option>
<option value="short">S hort</option>
<option value="sport">S port</option>
<option value="tv">Tele vision</option>
<option value="thriller ">Thriller</option>
<option value="war">War </option>
<option value="western" >Western</option>
</select>
</form>
</td>
<td width="150">
<form action='$_SERVE R[PHP_SELF]' method='get'>
<input type='hidden' name='t' value=''>
<input type='hidden' name='sortby' value='alpha'>
<select name="char" size="1" onchange="this. form.submit();" id="char" >
<option value="" selected>Browse Alphabetically</option>
<option value="%" >List All</option>
<option value="#" >Number</option>
<option value="a" >A</option>
<option value="b" >B</option>
<option value="c" >C</option>
<option value="d" >D</option>
<option value="e" >E</option>
<option value="f" >F</option>
<option value="g" >G</option>
<option value="h" >H</option>
<option value="i" >I</option>
<option value="j" >J</option>
<option value="k" >K</option>
<option value="l" >L</option>
<option value="m" >M</option>
<option value="n" >N</option>
<option value="o" >O</option>
<option value="p" >P</option>
<option value="q" >Q</option>
<option value="r" >R</option>
<option value="s" >S</option>
<option value="t" >T</option>
<option value="u" >U</option>
<option value="v" >V</option>
<option value="w" >W</option>
<option value="x" >X</option>
<option value="y" >Y</option>
<option value="z" >Z</option>
</select>
</form>
</td width="300">
<td><form action='$_SERVE R[PHP_SELF]' method='get'>
<input type='hidden' name='t' value=''>
<select name="sortby" size="1" onchange="this. form.submit();" id="char"

<option value="" selected>Sort By ----</option>
<option value="" >Show all titles </option>
<option value="recent" >Sort by recently added titles</option>
</select>
</form></td>
<td>&nbsp;</td>
</tr>
</table>
</center>
EOF;

return;
}

function format_rating($ rating){

if ($rating == "01") { $ratingf= "1"; }
elseif ($rating == "02") { $ratingf= "2"; }
elseif ($rating == "03") { $ratingf= "3"; }
elseif ($rating == "04") { $ratingf= "4"; }
elseif ($rating == "05") { $ratingf= "5"; }
elseif ($rating == "06") { $ratingf= "6"; }
elseif ($rating == "07") { $ratingf= "7"; }
elseif ($rating == "08") { $ratingf= "8"; }
elseif ($rating == "09") { $ratingf= "9"; }
elseif ($rating == "10") { $ratingf= "10"; }
return $ratingf;
}

function get_stars($rati ng){
global $star, $hstar;

if ($rating == 1) { $stars="<img src=$star>"; }
elseif ($rating == 2) { $stars="<img src=$star><img src=$star>"; }
elseif ($rating == 3) { $stars="<img src=$star><img src=$star><img
src=$star>"; }
elseif ($rating == 4) { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star>"; }
elseif ($rating == '5') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star>"; }
elseif ($rating == '6') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star><img src=$star>"; }
elseif ($rating == '7') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star><img src=$star><img src=$star>"; }
elseif ($rating == '8') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star><img src=$star><img src=$star><img
src=$star>"; }
elseif ($rating == '9') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star><img src=$star><img src=$star><img
src=$star><img src=$star>"; }
elseif ($rating == '10') { $stars="<img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star><img src=$star><img src=$star><img
src=$star><img src=$star><img src=$star>"; }
return $stars;
}

############### ############### ############### #####
############### ###############
?>

Mar 25 '06 #1
2 2326
Chris H wrote:
$pageprev = $page--;


This doesn't do what you think it does. What you have written is shorthand
for:

$pageprev = $page;
$page = $page - 1;

What you want is:

$pageprev = $page - 1;

Ditto with your use of ++.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Mar 25 '06 #2
thanks that worked

"Toby Inkster" <us**********@t obyinkster.co.u k> wrote in message
news:tp******** ****@ophelia.g5 n.co.uk...
Chris H wrote:
$pageprev = $page--;


This doesn't do what you think it does. What you have written is shorthand
for:

$pageprev = $page;
$page = $page - 1;

What you want is:

$pageprev = $page - 1;

Ditto with your use of ++.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Mar 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2802
by: Kurzman | last post by:
Let me know what you think about the following code: DECLARE @MaxIdValue int DECLARE @MaxSortFieldValue nvarchar(50) SELECT TOP 1 @MaxIdValue = , @MaxSortFieldValue = FROM ( SELECT TOP PageNumber*RowsPerPage , FROM MyTable WHERE (FilterCondition) ORDER BY , ) T
11
2778
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by going to url's like mywebsite/gallery.php?category=landscape Although the above worked perfectly...
0
1461
by: Sheau Wei | last post by:
I am using php version 4.3.3. The below was my pagination code. My problem is that when i run this code in my computer, i wall fail because of the hyperlink of the pagination not function when i click it. But when i run in other people computer, It was no problem at all. I wonder to know what wrong to my coding . Is it different version of php also reflect the output? <? //required file for database connection require("config.php");...
2
1854
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from table with pagination form data's are retaining if i select from first page but data not retaining if i select option from other than 1st page. i m using hidden field in pagination page. Thanks stalin
1
6851
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows links for all 8 pages. Previous 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 Next i want to...
16
2776
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
1
3555
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty quickly but I'm running into a stumbling block that I just can't seem to get around. I think I know what the problem is, and I'm pretty confident in a work around, but it's not quite what I had hoped for so I thought I'd pick some of the experts brains...
4
3574
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank. I have seen people mention this problem, and they have been told that a variable is...
2
2593
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title>
0
8962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9463
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4822
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3273
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.