SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL database controls

    I've been searching the net for this but I cant seem to find anything on it. Does anyone know if its even possible to select a certain line out of a databse? such as just taking line 10-20 or just start from 50? I'm trying to make a simple paging script for my site. Hoping I wont have to just start from scratch with the for() loops and what not.

  2. #2
    SitePoint Enthusiast fredanthony's Avatar
    Join Date
    Aug 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wulf
    I've been searching the net for this but I cant seem to find anything on it. Does anyone know if its even possible to select a certain line out of a databse? such as just taking line 10-20 or just start from 50? I'm trying to make a simple paging script for my site. Hoping I wont have to just start from scratch with the for() loops and what not.
    PHP Code:
    SELECT FROM tablename LIMIT 1020 
    This will return 20 records, starting with the 11th, indexes in databases begin at 0 when it comes to LIMITs. I am of course assuming by "line" you mean "row".

  3. #3
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you wouldn't happen to know how to tell what line of the database a specific person is?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    how do you know which person is which person? by name? person_id?

    do you know what a primary key is? does your table have a primary key?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean if joesmith is the 27th person on the list and he logs in and checks the database... I want the database to start the list with joesmith and list the next 10 people... a primary key wont help with that, cuz people come and go so the numbers (if used the the PK) will have gaps in them...

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    there is no 27th position

    rows in a relational database are not stored in any particular sequence

    primary keys are not necessarily numbers

    any time you are looking for "a simple paging script" you must realize that you cannot do it unless you do it with regard to the values in a particular column

    so if you were going by username, then you could ask "what are the next 10 usernames that collate alphabetically after 'joesmith'?"

    but notice that this is with regard to the actual values in the column, and not some "line number"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    Non-Member wulf's Avatar
    Join Date
    Jul 2006
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well what code could I use to do that? Also is it possible to get the previous 10. What I'm making is a databse where it starts with your username... it is ordered by a number which doesn't represent your usename but your activeness... so joesmith has an activeness of 10... since he's logged in it would show him first then the next 10 people with higher activeness and if he presses the back button that page would show the previous 10.

    I'm pretty good with coding the only problem is when I dont know the commands... and I cant seem to find the commands for this. I've checked google time and time again.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by wulf
    well what code could I use to do that?
    SELECT ...
    FROM ...
    ORDER BY something
    LIMIT somenumber, someothernumber

    because it is a paging algorithm, by definition controlled by an application language (e.g. php), you are responsible for feeding this query with the appropriate values to the database
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •