TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-08-2007, 10:22 AM   #1 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 27
Thanks: 0
crazyryan is on a distinguished road
Default Mod_rewrite & Pagination

Right, this is where I'm at ..

PHP Code:
$total mysql_query("select count(*) from games where id ='$id'");
$tot mysql_result($total0);
        
if (
is_numeric($_GET['page'])){
$page $_GET['page'];
}else{
$page 1;
}

$limit 1;

$start = ($page $limit) - $limit;

$query mysql_query("select * from games where catid = '$id' LIMIT $start$limit"); 

I'm just having problems showing the correct links, e.g.
PHP Code:
if ((($start $page) - $limit) > 0){
            
$page $page-1;
   echo 
'<a href="/category/' $id '/page-' $page '.html">Previous</a>';
               
$page $page+1;
            }
            
            if ((
$start $page) < $tot){
            
$page $page+1;
   echo 
'<a href="/category/' $id '/page-' $page '.html">Next</a>';
   
$page $page-1;

That works fine, kind of, it shows next and it shows previous, but it never shows them both at the same time, so I only ever get 2 pages of results.

Anyone know why?
crazyryan is offline  
Reply With Quote
Old 12-08-2007, 10:38 AM   #2 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

wouldn't it be easier to put

PHP Code:
if ($page 1){
          
   echo 
'<a href="/category/' $id '/page-' $page-'.html">Previous</a>';
        
            }
            
if (
$start $tot){
   
   echo 
'<a href="/category/' $id '/page-' $page+'.html">Next</a>';
 

__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 12-08-2007, 10:41 AM   #3 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 27
Thanks: 0
crazyryan is on a distinguished road
Default

I'm not sure, but even still .. it doesnt show next/previous on 1 page.
crazyryan is offline  
Reply With Quote
Old 12-08-2007, 10:57 AM   #4 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

php Code:
if ($page > 1){
         
   echo '<a href="/category/' . $id . '/page-' . $page-1 . '.html">Previous</a>';
       
            }
           
if ($start =< $tot){
   
   echo '<a href="/category/' . $id . '/page-' . $page+1 . '.html">Next</a>';
 
}

You should refer to How to paginate the fetched data from the database?
Haris is offline  
Reply With Quote
Old 12-08-2007, 11:00 AM   #5 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 27
Thanks: 0
crazyryan is on a distinguished road
Default

Thanks, that helps a bit, I've set my limit to 1 for testing and I have 5 rows, and it only goes up to page 3 and then says previous again.
crazyryan is offline  
Reply With Quote
Old 12-08-2007, 11:02 AM   #6 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by crazyryan View Post
Thanks, that helps a bit, I've set my limit to 1 for testing and I have 5 rows, and it only goes up to page 3 and then says previous again.
Post Updated.

Edit: Does $tot returns 5?

Edit2: Why are you decreasing 1 from $start on every page? $start = ($page * $limit) - $limit;
Haris is offline  
Reply With Quote
Old 12-08-2007, 11:18 AM   #7 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 27
Thanks: 0
crazyryan is on a distinguished road
Default

Okay, turns out I had an error in my query.

Your thing works Haris almost, it shows one extra next when it's not needed.
crazyryan is offline  
Reply With Quote
Old 12-09-2007, 02:47 PM   #8 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 27
Thanks: 0
crazyryan is on a distinguished road
Default

Bump, any solution to my post above?
crazyryan is offline  
Reply With Quote
Old 12-11-2007, 10:23 AM   #9 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Please note that mysql_result is 'deprecated'/very slow and therefore you should use the following function to get your results:

PHP Code:
$aRow mysql_fetch_array($pTotalMYSQL_NUM);
$iTotal $aRow[0]; 
Edit: Also you could better do COUNT(Id) instead of COUNT(*). It saves resources/memory and will be quicker.
maZtah is offline  
Reply With Quote
Old 10-22-2012, 09:14 AM   #10 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Old 01-29-2013, 11:47 AM   #11 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Organizers said Coach Outlet Online was opportune because the battle’s 150-year anniversary is in December, and Fredericksburg Coach Factory Outlet has been preparing to mark the sesquicentennial. in the new agreement is that Coach Outlet Online revolutionary councils from 14 Syrian provinces now each have a representative, though not all live Coach Online Outlet in Syria. The hope is that will bind the coalition to those inside the country. Perhaps Coach Bags Outlet the most important body the new group is expected to form is a Revolutionary Military Council Coach Factory Online to oversee the splintered fighting organizations and to funnel both lethal and nonlethal Coach Factory Outlet military aid to the rebels. It should unite units of the Free Syrian Army, various militias Coach Outlet Store Online and brigades in each city and large groups of defectors. Before the ink was even dry on the Coach Outlet Store final draft, negotiators hoped that it would bring them the antiaircraft missiles they crave to Coach Factory Stores take on the Syrian Air Force. The United States and Britain have offered only Coach Handbags Outlet nonmilitary aid to the uprising. A similar attempt by the Syrian National Council to Coach Factory Store supervise the military never jelled. Organizers said funding was too haphazard. Eventually foreign Coach Factory Online governments like Qatar and Saudi Arabia, which are financing and arming the rebels, found Coach Factory Online their own favorite factions to deal with. Foreign leaders notably including Secretary of State Coach Outlet Hillary Rodham Clinton urged this unification largely so they could coordinate their Coach Factory Outlet efforts and aid through a group of technocrats. Once it receives international recognition, the Coach Outlet Store Online coalition is supposed to establish a temporary Coach Outlet Online military never jelled.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 04:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design