Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1443 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

pagination?

Thread title: pagination?
Closed Thread    
    Thread tools Search this thread Display Modes  
09-01-2007, 06:31 AM
#1
Randy is offline Randy
Status: Sin Binner
Join date: Jan 2007
Location:
Expertise:
Software:
 
Posts: 1,121
iTrader: 13 / 100%
 

Randy is on a distinguished road

Send a message via MSN to Randy

  Old  pagination?

ok, so i spent awhile reading alot of tutorials and things on how to do it and i just don't get it. im reading the one by adam over at pixel2life but i dont get how you add content and such.

Code:

PHP Code:
<?php

    
if($_GET['page']) // Is page defined?

    
{

        
$page $_GET['page']; // Set to the page defined

    
}else{

        
$page 1// Set to default page 1

    
}

$max 5// Set maximum to 10

 

$cur = (($page $max) - $max); // Work out what results to show

 

$getdata mysql_query("SELECT * FROM `table` ORDER BY `id` DESC LIMIT $cur$max") or die(mysql_error()); // select the results

$data mysql_fetch_array($getdata); // get the data

 

$counttotal mysql_query("SELECT * FROM `table` ") or die(mysql_error()); // select all records        

$counttotal mysql_num_rows($counttotal); // count records

 

$total_pages ceil($counttotal $max); // dive the total, by the maximum results to show 

 

if($page 1){ // is the page number more than 1?

                
$prev = ($page 1); // if so, do the following. take 1 away from the current page number

                
echo '<a href="?page=' $prev '">« Previous</a>'// echo a previous page link

                
}

 

for(
$i 1$i <= $total_pages$i++) // for each page number

                
{

                    if(
$page == $i// if this page were about to echo = the current page

                        
{

                            echo
'<b>' $i .'</b> '// echo the page number bold

                                
} else {

                            echo 
'<a href="?page=' $i '">' $i '</a> '// echo a link to the page

                        
}

                }

 

if(
$page $total_pages){ // is there a next page?

                    
$next = ($page 1); // if so, add 1 to the current

                
echo '<a href="?page=' $next '">Next »</a>'// echo the next page link

                    


?> // end php script
SCRIPT COMES STRAIGHT FROM ADAM AT PIXEL2LIFE, AND ALL RIGHTS TO IT ARE HIS.

please help me on finding out how to add content.

Thank you.

Sincerely,
Randy

09-01-2007, 08:53 PM
#2
Randy is offline Randy
Status: Sin Binner
Join date: Jan 2007
Location:
Expertise:
Software:
 
Posts: 1,121
iTrader: 13 / 100%
 

Randy is on a distinguished road

Send a message via MSN to Randy

  Old

anybody?

09-01-2007, 09:24 PM
#3
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

I've always thought pagination sounded somewhat paganistic. I wouldn't be surprised if pagination burns a witch on the heath every solstice.

Has Adam at Pixel2Life never heard of SQL_CALC_FOUND_ROWS? Terrible code that is. The second query is just disgusting. One big awful and very slow query that even a mere 500 record table would bring on a discernible decrease in page load times.

As for your content, it's dragged straight from the database so all the data will be dynamic data. At the moment it is procuring the data from a table aptly labeled, table.

09-06-2007, 02:06 PM
#4
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

I actually wrote a post on another forum regarding the SQL_CALC_FOUND_ROWS if anybody is interested. That can be viewed here. It really is crucial, Randy, if you're going to be using the pagination as listed on Pixel2Life then your database will end up flat on its back with the load. Of course, COUNT(*) is another way to achieve this as it will get the data straight from the attached table information.

Closed Thread    


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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed