MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

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 November 28th, 2005, 06:19 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
Selecting next 10 rows in table?

Code:
$sql = "SELECT 1, 2, 3 FROM tbl1 ORDER BY 1 DESC LIMIT 0, 10";


So, I loop out the 10 last entrys from the database...nothing special so far.

What I like to do is to make a link that will show the next 10 entrys. Any smart way of doing it?

Reply With Quote
  #2  
Old December 2nd, 2005, 04:39 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
wow... either a very tricky question or a very low activity here :P

Reply With Quote
  #3  
Old December 2nd, 2005, 08:33 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I'm guessing it's pagination you're looking for? (to display results on different pages)
Perhaps Google will help you figure it out: php pagination

As a quick tip... you may want to pass a variable to your results page indicating which page your on..

Example, if your URL was: http://www.example.com/results.php?page=2
PHP Code:
 $no_of_entries=10;
$starting_point=($_GET['page']*$no_of_entries);
$sql "SELECT 1, 2, 3 FROM tbl1 ORDER BY 1 DESC LIMIT $starting_point, $no_of_entries"
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #4  
Old December 7th, 2005, 06:50 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
This is a snippet of what I finally came up with, since there finally was an answer in th thread I thought I post how I solved it.

PHP Code:
 $sql "SELECT col1, col2, col3  FROM tbl1 ORDER BY col1 DESC";
    
$res mysql_query($sql) or die(mysql_error());

    if (!isset(
$pagenr) || $pagenr == || $pagenr == ""){$pagenr 1;}

    
$perPage 15;
    
$numRows mysql_num_rows($res);
    
$numPages $numRows/$perPage;
    
    if (
$pagenr != 1) {
        
mysql_data_seek($res,(($pagenr-1)*$perPage));
    }
    
    
$x 0;
    
    echo 
"<table width='500' cellspacing='2' cellpadding='2'><tr><td align='center'>\n";

        for(
$i 1$i < ($numPages+1); $i++) {
            if (
$i == $pagenr){
                echo 
'<b>'.$i.'</b> | ';
            } else {
                echo 
'<a class="topic" href="?a='.$kat.'&pagenr='.$i.'">'.$i.'</a> | ';
            }
        }
    echo 
"</td></tr><tr><td class='arrowCell'>\n";
        
    if(
$pagenr 2) {echo '&nbsp;&nbsp; | '; }else{echo '<a class="topic" href="?a='.$kat.'&pagenr='.($pagenr-1).'"><img class="arrow" src="gfx/arrow_left.gif" alt="Bakåt" title="Bakåt""></a> | ';}
    if(
$pagenr >= $numPages) {echo '&nbsp;&nbsp;'; }else{echo '<a class="topic" href="?a='.$kat.'&pagenr='.($pagenr+1).'"><img class="arrow" src="gfx/arrow_right.gif" alt="Framåt" title="Framåt"></a>';}

    echo 
"</td></tr></table>\n";


    while((
$row mysql_fetch_row($res)) && ($x $perPage)) 


The above prints a row of page numbers...code might look a bit tacky I know...but it does the job and I might rewrite it later
Comments on this post
MadCowDzz agrees: Thanks for following up Laban!

Reply With Quote
  #5  
Old December 7th, 2005, 07:37 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Thanks for following up Laban!
Hopefully this helps others in your situation.

Reply With Quote
  #6  
Old December 8th, 2005, 06:10 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
My pleasure MadCow...where's my rep points??

The code might have to be explained a bit more, will do so if required.

Reply With Quote
  #7  
Old December 8th, 2005, 08:35 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
There's yer rep points! =P

Pagination is a common request here...
Hopefully your code helps others

Reply With Quote
  #8  
Old December 8th, 2005, 09:34 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
Pagination would be nice to master, perhaps there should be a article about it. I'll see if I can whack something together in more detail based on the above sample.

Thanks for the points :P

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Selecting next 10 rows in table?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway