SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, before I asked how to get results alphabeticly, and how to limit the amount of results I get by 20.

    Now how do I use these together?
    I understand this is probaly a lenghty process so if you dont really want to type it all out, at least redirect me to a site that can teach me this?

    the list must first be sort from A-Z then pick 20 results from it?

    thanx
    Ryan Lahay

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this from a SQL friendly database? if so, something similar to the following will be in (at the end of) your query :

    ORDER BY sometablename ASC LIMIT 20

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it is

    so it owuld be like..

    $sql= "SELECT * FROM list ORDER BY sometablename ASC LIMIT 20";

    now lets say i have another collum of entries... and they contain values that are something like

    red
    blue
    green
    red
    green
    green
    green
    red

    that collum was maybe.. er.. color ?

    now lets say i hve another collom with something like
    a
    v
    g
    a
    f
    d
    h
    a
    called letter

    k... now I want to have a statement that will select only the color stored in $variable and then from those results list htem alphabeticly based on the letter collum, and for an extra twist, only have a max of 20

  4. #4
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql= "SELECT * FROM list ORDER BY letter DESC LIMIT 20";

    You would replace 'sometablename' with 'letter', since that is the column you want to order your results by.

    BTW--I think it would be DESC instead of ASC. ASC would be backward-alphabetically.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sounds like this is what you're after :

    $sql = "SELECT * FROM list WHERE color='$variable' ORDER BY sometablename ASC LIMIT 20";
    Last edited by Philip Olson; May 14, 2001 at 22:14.

  6. #6
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    list is the name of the table that has all these values..
    does that replace sometablename ?

    Im pretty sure it does .. just double checkin

  7. #7
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    list is the name of the table that has all these values..
    does that replace sometablename ?

    Im pretty sure it does .. just double checkin

    or is it supposed to be the collum that I want teh data to be sorted alphabeticly buy ..which in this case is "letter"

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sounds like you want sometablename to be 'letter'. In fact, whenever you see me writing sometablename pretend i wrote somecolumnname :-) oops!

  9. #9
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx

    been a great help

  10. #10
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about selecting everything that says an exact value (like "cow") from 3 different collums.. lets say the three are called "col1" "col2" "col3"

    after getting those results, alphabeticly sort them by another collum called "name"

    Do i just put three WHERE statement things in it?
    Last edited by slighltywhacked; May 16, 2001 at 15:56.


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
  •