Jump to content

could i do this?


neo777ph

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.