only1perky Posted January 29, 2009 Share Posted January 29, 2009 Hi guys, I am querying my database depending on the first letter of the field using: mysql_select_db($database_connuser, $connuser) or die; $query = "SELECT * FROM drinking WHERE venue LIKE '{$Letter}%'"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); What I would like to happen is if the first word of $row['venue'] is THE then to ignore it and move on to the next word. Can someone help me out? Quote Link to comment Share on other sites More sharing options...
Mikedean Posted January 29, 2009 Share Posted January 29, 2009 You should be able to do it in the MySQL query. mysql_select_db($database_connuser, $connuser) or die; $query = "SELECT * FROM drinking WHERE REPLACE(venue, 'The ', '') LIKE '{$Letter}%'"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); I think that'll work. Quote Link to comment Share on other sites More sharing options...
printf Posted January 29, 2009 Share Posted January 29, 2009 Or use NOT REGXP, that way you can ignore many different string starting whole words... $ignore = 'The|This'; $query = "SELECT * FROM drinking WHERE venue LIKE '" . $Letter . "%' AND venue NOT REGEXP '^[[:<:]]" . $ignore . "[[:>:]]';"; Quote Link to comment Share on other sites More sharing options...
only1perky Posted January 29, 2009 Author Share Posted January 29, 2009 Works perfectly, thank you people. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.