MySql Search %$query% from 2 Columns???

Currently when I perform a search using an HTML form for data in my database, I have the following code:

$result = mysqli_query($con,“SELECT * FROM businesses where name like ‘%$queried%’ or address like ‘%$queried%’ or industry like ‘%$queried%’”);

An example search would be “washington st” which brings up every business on washington street under the “address” column.

But If I did a search like “chipotle mexican grill washington st boston” it would return nothing. Even though the “name” column includes chipotle mexican grill.

Why isn’t it pulling up chipotle on washington st in boston specifically when I type it in?

Please help me!!

Without seeing more code it is difficult to discern how you are approaching this, but two things.

  1. You NEED to learn to use prepared statements. You are very vulnerable now and anyone with access to google could kill you database.

  2. How many results do you think you would get back with this,

SELECT * FROM businesses where name = ‘chipotle mexican grill washington st boston’

Which is essentially what you are doing. You could try to break the fields up into their respective categories. IE,
a search box for the name, another for the location, or a drop down like amazon uses to narrow where to look.

Sponsor our Newsletter | Privacy Policy | Terms of Service