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.. Quote Link to comment 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 " " Quote Link to comment 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? Quote Link to comment 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 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.