Web Analytics Made Easy -
StatCounter How can I select a range of data? - CodingForum

Announcement

Collapse
No announcement yet.

How can I select a range of data?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I select a range of data?

    Right now i am working on a user management system. I have a page that lists all of the users, but i only want it to show 20 users at a time with a link to go forward and backwards to see more users. How do I select a range of data from a mysql table? For example how would I output users 21-40?

    PHP Code:
                                $newest2 = @mysql_query("select * from users order by id asc");
                                echo 
    "<b>Members:</b><br><br>";
                                
    $a 0;
                                while(
    $user = @mysql_fetch_array($newest2))
                                {
                                    
    $a++;
                                    echo 
    "$a [ <a href='index.php?p=profiles&uid=$user[id]'>$user[username]</a> ]<br>";
                                } 
    I have a feeling that I am missing something that couldnt be more obvious.

    Anyways, how can it be done?

    -Matt
    -Matt

  • #2
    How do I select a range of data from a mysql table? For example how would I output users 21-40?
    by using the LIMIT clause. Like

    select * from users order by id asc LIMIT 20, 20

    it's LIMIT x,y where x = the ofset (0 based count) and y = the number of records to return

    If you want to display a list like previous - Page1 - Page2 - Page 3 - Next then run a search here or google fro recorset paging. Plenty of tutorials aout that + plenty of free classes at www.
    phpclasses.org
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment

    Working...
    X