473,390 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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_exists('connect_to_mysql')){

function connect_to_mysql(){

global $db_location,$db_username,$db_password,$db_databas
e;

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

return;
}
}

if (!function_exists('error_message')){

function error_message($text){

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

return;

}

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

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

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

echo "<table width=\"820\" border=\"0\" cellspacing=\"0\"
cellpadding=\"0\">";
echo "<tr><td><center><font size=\"6\">$title</font></center></td></tr>";
echo "<tr><td><center>Currently $how_many movies in
database</center></td></tr>";
echo "<tr><td><center><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=\"66ccff\"></th>";
echo "<th width=\"400\" bgcolor=\"66ccff\"><strong><a
href=\"index.php?t=&sortby=title\">Movie Title</a> </strong></th>";
echo "<th width=\"260\" bgcolor=\"66ccff\"><strong><a
href=\"index.php?t=&sortby=rating\">Rating</a></strong></th>";
echo "<th width=\"125\" bgcolor=\"66ccff\"><strong><a
href=\"index.php?t=&sortby=cat\">Genre</a></strong></th>";
echo "</tr>";

connect_to_mysql();

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

$bgcolor = "#E0E0E0"; // light gray
$result = $sql;
$z = 1;
while($rs = mysql_fetch_array($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($rating);

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

echo("<a href=\"index.php?t=&page=$pageprev\">PREV".$limit. "</a> ");
}else{
echo("PREV".$limit." ");
}

$numofpages = $totalrows / $limit;

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

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

echo("<a href=\"index.php?t=&page=$pagenext\">NEXT".$limit. "</a>");
}else{
echo("NEXT".$limit);
}
##############################################

return;

}

//was browse_by_cat()
function quick_links(){

print <<<EOF
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#111111" width="820" id="AutoNumber1">
<tr>
<td width="100">
<form action='$_SERVER[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="adventure">Adventure</option>
<option value="animation">Animation</option>
<option value="biography">Biography</option>
<option value="comedy">Comedy</option>
<option value="crime">Crime</option>
<option value="documentary">Documentary</option>
<option value="drama">Drama</option>
<option value="educational">Educational</option>
<option value="family">Family</option>
<option value="fantasy">Fantasy</option>
<option value="horror">Horror</option>
<option value="music">Music</option>
<option value="musical">Musical</option>
<option value="mystery">Mystery</option>
<option value="romance">Romance</option>
<option value="scifi">Sci-Fi</option>
<option value="short">Short</option>
<option value="sport">Sport</option>
<option value="tv">Television</option>
<option value="thriller">Thriller</option>
<option value="war">War</option>
<option value="western">Western</option>
</select>
</form>
</td>
<td width="150">
<form action='$_SERVER[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='$_SERVER[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($rating){
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 2289
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**********@tobyinkster.co.uk> wrote in message
news:tp************@ophelia.g5n.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
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...
11
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. ...
0
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...
2
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...
1
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...
16
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) ...
1
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...
4
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,...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.