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
https://forums.phpfreaks.com/topic/42099-could-i-do-this/
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
https://forums.phpfreaks.com/topic/42099-could-i-do-this/#findComment-204193
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.