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? Link to comment https://forums.phpfreaks.com/topic/142947-ignore-the-if-in-string/ 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. Link to comment https://forums.phpfreaks.com/topic/142947-ignore-the-if-in-string/#findComment-749490 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 . "[[:>:]]';"; Link to comment https://forums.phpfreaks.com/topic/142947-ignore-the-if-in-string/#findComment-749495 Share on other sites More sharing options...
only1perky Posted January 29, 2009 Author Share Posted January 29, 2009 Works perfectly, thank you people. Link to comment https://forums.phpfreaks.com/topic/142947-ignore-the-if-in-string/#findComment-749498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.