DanielW Posted April 25, 2014 Share Posted April 25, 2014 When I search my database I can only get results returned back if I search for only a single letter, when I type a whole word I get 0 matches returned. I have the following if statment where I have been trying to get the correct regular expressions but I am unsure where I am going wrong, What expression would I need to use to be able to type in a city name for example Tucson and get a result? if($_POST['filter1'] == "City") { $sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE city_name LIKE '%$searchquery%'"; //$sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE MATCH (city_name) AGAINST ('searchquery')"; //$sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE city_name REGEXP '%$searchquery%'"; } Link to comment https://forums.phpfreaks.com/topic/288020-regular-expressions-in-mysql/ Share on other sites More sharing options...
requinix Posted April 25, 2014 Share Posted April 25, 2014 The first form should work fine. Where is $searchquery getting its value? What is the value of $sqlCommand when it is being run and returning no results? Link to comment https://forums.phpfreaks.com/topic/288020-regular-expressions-in-mysql/#findComment-1477296 Share on other sites More sharing options...
DanielW Posted April 26, 2014 Author Share Posted April 26, 2014 Hi thanks for taking some time to look at my code $searchquersy gets its value from this line $searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']); the value of $sqlCommand when it is being run i not sure I have tried to see in the chrome developer consle but I cannot find what it is, i am pretty new to php Link to comment https://forums.phpfreaks.com/topic/288020-regular-expressions-in-mysql/#findComment-1477340 Share on other sites More sharing options...
Ch0cu3r Posted April 26, 2014 Share Posted April 26, 2014 the value of $sqlCommand when it is being run i not sure I have tried to see in the chrome developer consle but I cannot find what it is, i am pretty new to php PHP code never reaches the browser. So the console wont be able to tell you the value of $sqlCommand. Instead you echo $sqlCommand in your code. $sqlCommand = "SELECT city_id AS id, city_name AS title FROM city WHERE city_name LIKE '%$searchquery%'"; echo $sqlCommand; // output the SQL query Link to comment https://forums.phpfreaks.com/topic/288020-regular-expressions-in-mysql/#findComment-1477341 Share on other sites More sharing options...
DanielW Posted April 26, 2014 Author Share Posted April 26, 2014 Hi the result of $sqlCommand when I get no results is Tucson which is indeed what i typed for the search Link to comment https://forums.phpfreaks.com/topic/288020-regular-expressions-in-mysql/#findComment-1477349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.