Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 01-07-2009, 01:36 PM   #1 (permalink)
v7n Mentor
 
Join Date: 10-13-03
Location: Atlanta, GA
Posts: 662
iTrader: 0 / 0%
Latest Blog:
None

Leon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of light
Help with Pagination

Hey Guys. I'm having a small problem with my pagination script [I did not right it, just modified it]. Basically it works great except for 1 thing, when you change the page (or go to the next one) it ignores the query and by that I mean let's say you have:
http://site.com/page.php?cat=1

That's your page, well you want to go to page Number to say:
http://site.com/page.php?cat=1&page=2

I can't get that to work because it's ignoring the address. Now I had an idea of how to fix that for like going to page # 2 but my method wouldn't work cause it would essentially keeping adding "page" to the address sooo I'm looking for help!

Here's the Code for the pagination:
PHP Code:
<?php 
// What Page are we on?
if (isset($_GET['pageno'])) {
   
$pageno $_GET['pageno'];
} else {
   
$pageno 1;
}
include (
'connect_avail.php');
$cats $_GET['cat'];
// Are any categories defined?
if (empty($cats)) {
    
$query "SELECT * FROM cat_ballpythons ORDER BY priority DESC";
} else {
    
    
$query "SELECT * FROM cat_ballpythons WHERE (";

    for (
$i 0$i count($cats); $i++) {
        
$cat mysql_escape_string(strip_tags($cats[$i]));
        
$query .= "keywords LIKE '%$cat%' ";
        if ((
$i+1) < count($cats)) {
            
$query .= "or ";
        }
    }
    
    
$query .= ") ORDER BY priority DESC";
    
}
$result = @mysql_query($query);
$query_data = @mysql_fetch_row($result);
$numrows mysql_num_rows($result);
$rows_per_page 2;
$lastpage ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
// Let's make sure we're not on a page that doesn't exsist.
if ($pageno $lastpage) {
   
$pageno $lastpage;
}
if (
$pageno 1) {
   
$pageno 1;
}
// Let's Setup our Queries shall we?
$limit 'LIMIT ' .($pageno 1) * $rows_per_page .',' .$rows_per_page;
if (empty(
$cats)) {
    
$query "SELECT * FROM cat_ballpythons ORDER BY priority DESC $limit";
} else {
    
    
$query "SELECT * FROM cat_ballpythons WHERE (";

    for (
$i 0$i count($cats); $i++) {
        
$cat mysql_escape_string(strip_tags($cats[$i]));
        
$query .= "keywords LIKE '%$cat%' ";
        if ((
$i+1) < count($cats)) {
            
$query .= "or ";
        }
    }
    
    
$query .= ") ORDER BY priority DESC $limit";
    
}
$result mysql_query($query);
?>
Like I said that part works great, no problems here. However what I need to fix is this:

PHP Code:
<? 
// Display the First Link and the Back Link
if ($pageno == 1) {
   echo 
"<img src='template/arrow_start.gif' border='0' /> <img src='template/arrow_back.gif' border='0' />";
} else {
   echo 
"<a href='{$_SERVER['PHP_SELF']}?pageno=1'><img src='template/arrow_start.gif' border='0' /></a>";
   
$prevpage $pageno-1;
   echo 
" <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><img src='template/arrow_back.gif' border='0' /></a> ";
}
// Show what page we are on, and how many there is.
echo " <strong>( Page $pageno of $lastpage )</strong> ";
// Display the Next Link and the Last Link
if ($pageno == $lastpage) {
   echo 
" <img src='template/arrow_forward.gif' border='0' /> <img src='template/arrow_last.gif' border='0' /> ";
} else {
   
$nextpage $pageno+1;
   echo 
" <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'><img src='template/arrow_forward.gif' border='0' /></a> ";
   echo 
" <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'><img src='template/arrow_last.gif' border='0' /></a> ";
}
?>
So Basically when I'm on page "page.php?cat=1" I want the link to go to Page 2 and still keep the ?cat=1 in there or whatever else may be in there. It isn't rare for my address to be like page.php?cat=1&cat=2&cat=3 etc.
Leon is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 01:50 PM   #2 (permalink)
Junior Member
 
Join Date: 01-04-09
Posts: 9
iTrader: 0 / 0%
Latest Blog:
None

Budois is liked by many
Now this might sound awfully stupid, but what I get from your script shouldn't you type in your adress bar http://site.com/page.php?cat=1&pageno=2 instead of http://site.com/page.php?cat=1&page=2
It seems to me that the page number is being selected by a variable pageno and not by page.
Budois is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 02:01 PM   #3 (permalink)
v7n Mentor
 
Join Date: 10-13-03
Location: Atlanta, GA
Posts: 662
iTrader: 0 / 0%
Latest Blog:
None

Leon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of light
Quote:
Originally Posted by Budois View Post
Now this might sound awfully stupid, but what I get from your script shouldn't you type in your adress bar http://site.com/page.php?cat=1&pageno=2 instead of http://site.com/page.php?cat=1&page=2
It seems to me that the page number is being selected by a variable pageno and not by page.
Yeah I wasn't really referencing my exact code when I was made those examples. What I think needs to look for a "?pageno=x" and remove it, and I know how to remove the "?pageno=" but not the actual number (since it changes)

Quote:
Originally Posted by Capo64 View Post
you could do <a href='{$_SERVER['PHP_SELF']}?cat={$_GET['cat']}&pageno=$nextpage'>

but i don't know about having cat defined multiple times, I didn't even know you were allowed to do that.

why don't you just change the cat variable to a string and make it like this:
?cat=1,2,3 then split the string and go from there.

Otherwise you can do a reg_replace on the $_SERVER['QUERY_STRING']
Because that would require me re-writing a seperate script that uses the same query.

This is what my addresses look like (or at least could look like):
PHP Code:
page.php?&cat[]=1&cat[]=
This is what it would look like if it's on say page 2:
PHP Code:
page.php?&cat[]=1&cat[]=2&pageno=

Last edited by Leon; 01-07-2009 at 02:13 PM..
Leon is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 01:51 PM   #4 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
you could do <a href='{$_SERVER['PHP_SELF']}?cat={$_GET['cat']}&pageno=$nextpage'>

but i don't know about having cat defined multiple times, I didn't even know you were allowed to do that.

why don't you just change the cat variable to a string and make it like this:
?cat=1,2,3 then split the string and go from there.

Otherwise you can do a reg_replace on the $_SERVER['QUERY_STRING']
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 03:02 PM   #5 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
You could create a snippet to generate the first part of the URL like this:

Code:
if (count($_GET['cat'])) { $qs = ''; foreach($_GET['cat'] as $cat) { $qs .= 'cat[]=' . $cat . '&'; } }
then have <a href="{$_SERVER['PHP_SELF']}?{$qs}{$pageno}">
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 03:54 PM   #6 (permalink)
v7n Mentor
 
Join Date: 10-13-03
Location: Atlanta, GA
Posts: 662
iTrader: 0 / 0%
Latest Blog:
None

Leon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of light
Quote:
Originally Posted by Capo64 View Post
You could create a snippet to generate the first part of the URL like this:

Code:
if (count($_GET['cat'])) { $qs = ''; foreach($_GET['cat'] as $cat) { $qs .= 'cat[]=' . $cat . '&'; } }
then have <a href="{$_SERVER['PHP_SELF']}?{$qs}{$pageno}">
I had to modify it a little but it's perfect! Thank you very much
Leon is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2009, 04:28 PM   #7 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Happy to help
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Pagination of a directory Oliver Coding Forum 7 06-03-2008 11:38 AM
Pagination Help Xsnoboard Coding Forum 2 12-14-2006 11:11 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 07:05 AM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.