neo777ph Posted March 10, 2007 Share Posted March 10, 2007 can i do this on my sql statement? I am doing a search engine $sql = "SELECT id,transno,vendorname,vendorid,nature FROM tblvendor WHERE". str_replace(" ","_",vendorname ). "like '%$ven%' "; there are vendorname entries on my database that are written with an "_".. example John_Paul.. So if my end-user inputs "John Paul" to search for.. The search would not include those vendor name with "John_Paul". I want it also to be included.. Link to comment https://forums.phpfreaks.com/topic/42099-could-i-do-this/ Share on other sites More sharing options...
Tyche Posted March 10, 2007 Share Posted March 10, 2007 Not as it stands if you try $regexpstr = str_replace(" ","[_ ]",$ven); $sql = "SELECT id,transno,vendorname,vendorid,nature FROM tblvendor WHERE vendorname REGEXP '$regexpstr' "; Then that should work so in your example "John Paul" is changed to "John[_ ]Paul" which when used as a RegEx in MySQL will search for "_" or " " Link to comment https://forums.phpfreaks.com/topic/42099-could-i-do-this/#findComment-204193 Share on other sites More sharing options...
neo777ph Posted March 10, 2007 Author Share Posted March 10, 2007 tnx a lot.. what is the diference between REGEXP and LIKE? Link to comment https://forums.phpfreaks.com/topic/42099-could-i-do-this/#findComment-204196 Share on other sites More sharing options...
Tyche Posted March 10, 2007 Share Posted March 10, 2007 Not a lot - both are pattern matching functions REGEXP can be used to perform pattern matching which is more complex than LIKE - but there are overheads - I'd recommend always using LIKE where you can - and only use REGEXP when a LIKE can't handle the query Link to comment https://forums.phpfreaks.com/topic/42099-could-i-do-this/#findComment-204197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.