-
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
-
$result = mysql_query("SELECT title FROM my_table WHERE title REGEXP '[a-d]'");
I figured it out http://www.SitePoint.com/forums/smile.gif
------------------
Visit the Sitepoint Chat!
http://www.sitepoint.com/forums/chat.php3
-
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 =)
-
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 http://www.SitePoint.com/forums/smile.gif How could this title be placed under S, not T?
-
Whoooie, another reply to myself! http://www.SitePoint.com/forums/smile.gif
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.
-
OK... I think I really have it figured out this time. http://www.SitePoint.com/forums/smile.gif
$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
-
-
Dang, you guys are good! http://www.SitePoint.com/forums/smile.gif
------------------
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!