General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 30th, 2002, 08:20 PM
deff_lee deff_lee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 11 deff_lee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
google style next prev button

Hi all,

i want to know how to make next prev button like google
with php and mysql ..

thank's

-- deff

Reply With Quote
  #2  
Old May 30th, 2002, 08:45 PM
epyon epyon is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Chicago
Posts: 22 epyon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
with LIMIT.
look it up.

Reply With Quote
  #3  
Old May 30th, 2002, 09:58 PM
CopeLand CopeLand is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Toronto
Posts: 40 CopeLand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I think one of the devarticles team wrote an article on that somewhere. try looking in the php or mysql category. i remember reading the article, was fairly good.

basically you just use the LIMIT keyword as epyon said and filter the number of records displayed
__________________
i am cope. i drink coke. i am in hope.i am cope. i drink coke. i am in hope.i am cope. i drink coke. i am in hope.

Reply With Quote
  #4  
Old May 30th, 2002, 09:59 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
we have a article on this very subject try, Building A Dynamic MySQL Paging Class With PHP
that should cover everything you need to know, if you still have any questions, please post them here, id be glad to help!

Reply With Quote
  #5  
Old May 30th, 2002, 10:38 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
just to add to that last post, i just read that article, and it may be a bit advanced for your needs, if you would like i have made a simpler prev/next for my sites, that i could post for you if you would like, its just a few lines of code

Reply With Quote
  #6  
Old May 31st, 2002, 02:01 AM
deff_lee deff_lee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 11 deff_lee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank's before ben

i'd love to, please post u're own script, and i'll learn

-- deff

Reply With Quote
  #7  
Old May 31st, 2002, 05:27 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
ok here it is

it comes in two parts

PHP Code:
 $display_number 20;  //number of table rows it pulls from the database.




                     
$query1 mysql_query("SELECT * FROM table_name WHERE field=$var"); // run the query here

                     
$num_results mysql_num_rows($query1);

             if (!isset(
$num_pages))
                 {
                     if(
$num_results $display_number)
                         {

                             
$num_pages ceil ($num_results/$display_number);

                         }
                     elseif(
$num_results 0)
                         {

                             
$num_pages 1;

                         }
                     else
                         {

                         }

                             
$start 0;
                 } 


ok this part finds out how many pages we need, all you have to do is set the query and how many rows for each page.
once you have that, you can place this next section of php anywhere, and it will generate the links for you.

PHP Code:
<?php

                                              
if ($num_pages 1)
                                                  {

                                                      if (
$start == 0)
                                                          {

                                                          
$current_page 1;

                                                          }
                                                      else
                                                          {

                                                          
$current_page = ($start/$display_number) + 1;

                                                          }

                                                      if (
$start !=0)
                                                          {

                                                              echo 
'<b><a class="white" href="news.php?start=' . ($start $display_number) . '&num_pages=' $num_pages '">Previous</a></b> '//previous button

                                                          
}
                                                      else
                                                          {

                                                          echo 
'Previous ';

                                                          }

                                                      for (
$i 1$i <= $num_pages$i++)
                                                          {

                                                              
$next_start $start $display_number;

                                                              if (
$i != $current_page)
                                                                   {

                                                                   echo 
'<b><a class="white" href="news.php?start=' . (($display_number * ($i 1))) . '&num_pages=' $num_pages '">' $i '</a></b> '// generates the numbers for the pages

                                                                   
}
                                                              else
                                                                   {

                                                                   echo 
'<b  class="black">' .    $i '</b> ';

                                                                   }

                                                          }


                                                      if (
$current_page != $num_pages)
                                                          {

                                                          echo 
'<b><a class="white" href="news.php?start=' . ($start $display_number) . '&num_pages=' $num_pages '">Next</a></b>'// next button

                                                          
}

                                                      else
                                                          {

                                                          echo 
'Next';

                                                          }


                                                  }



                                              
?>


hope this helps

Reply With Quote
  #8  
Old June 1st, 2002, 09:07 PM
deff_lee deff_lee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 11 deff_lee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank's Ben

it's usefull ..

-- deff

Reply With Quote
  #9  
Old July 23rd, 2002, 09:14 AM
Kevin Holdridge Kevin Holdridge is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 1 Kevin Holdridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Building A Dynamic MySQL Paging Class With PHP

This article looks very good - unfortunately the support files are no longer available at the old link - anybody know where to go to get hold of the recnav class file and sample script?

Reply With Quote
  #10  
Old July 24th, 2002, 10:56 PM
amorphosium amorphosium is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Melbourne
Posts: 1 amorphosium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy A NewBie Problem

Hi all...

I've tried the code provided by Ben (thanks Ben) I have used them and it generated the page links very well.... however... only the first page worked... the others didn't.

What I meant was:

The MySQL query takes two arguments in the form of $prod_group and $order_by from two drop down list, where once it is submitted, the $prod_group and $order_by is used in this query:

$result = mysql_query("SELECT * FROM products WHERE prod_group = '$prod_group' ORDER BY $order_by ASC", $link_id);

So, when I used Ben's script, I do not know how to modify it so that when I click on the page links, it submitted this:

productorder2.php?prod_group=GC&order_by=prod_brand&submit=Submit&start=2

rather than just this:

productorder2.php?start=2

How do I achieve this?

I'm sorry if I'm being unclear... but I've just started programming about a month ago..

Thank you very much in advance.. thanks..

Reply With Quote
  #11  
Old July 16th, 2003, 01:19 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Talking

Hi ben,
i have tried your google style paging and it works to an extent. When i click page 2, it displays the same results listed on page 1, any ideas why this may be?

thanks
__________________
regards,


Fulton

Reply With Quote
  #12  
Old July 19th, 2003, 09:19 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Where in this code do i put my "while" loop?

Reply With Quote
  #13  
Old December 14th, 2003, 05:52 PM
dr1000 dr1000 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: New Orleans
Posts: 1 dr1000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
showing different stuff

Thanks very much, Ben, for this code. I spent all day yesterday with something much harder; it never worked. I got this going in about an hour.

I don't know if this is the best way to make it show different items, but the way I did it was to add to my query:

"limit $start, $display_number"

URL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > google style next prev button


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


<