SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Eugene, OR
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If I use the following statement, I'm able to get all titles that begin with the letter a.

    $result = mysql_query("SELECT title FROM my_table WHERE title like 'a%'");

    However, what do I do if I want to get all the titles that begin with the letters a,b,c and d?

    Thanks for you help,

    Adam

    ------------------
    Visit the Sitepoint Chat!
    http://www.sitepoint.com/forums/chat.php3

  2. #2
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Eugene, OR
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result = mysql_query("SELECT title FROM my_table WHERE title REGEXP '[a-d]'");

    I figured it out

    ------------------
    Visit the Sitepoint Chat!
    http://www.sitepoint.com/forums/chat.php3

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL!

    I would have done that like this:

    $result = mysql_query("SELECT title FROM my_table WHERE title LIKE 'a%' OR title LIKE 'b%' OR title LIKE '%c' etc. etc. ");

    Shows how much I know =)

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On a somewghat related note, what would be the best way to deal with titles that start with "The". Often such titles are shown in indexes like this: "Search for Spock, The" or whatever How could this title be placed under S, not T?

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoooie, another reply to myself!

    I would advise against using the REGEXP solution! I tried it out... it would select all titles containing a, b, c or d, not just select the ones that *start* with them.

  6. #6
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Eugene, OR
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK... I think I really have it figured out this time.

    $result = mysql_query("SELECT * FROM my_table WHERE title REGEXP '^[a-eA-E]'");

    The little ^ tells it just to search for the first letter, and a-eA-E has it search both lowercase and uppercase titles.


    ------------------
    Visit the Sitepoint Chat!
    http://www.sitepoint.com/forums/chat.php3

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's it!

    ------------------

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dang, you guys are good!


    ------------------
    Chris Bowyer chris@mycoding.com
    MyCoding.com: Visit for Launch Notification!
    DomainMailings.com: Who Says All The Good Ones Are Taken?
    MovieForums.com: Talk About Your Favorite Flicks!


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
  •