Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's no way to just search everything in a database using MySql, you'll still need to choose which columns to search in which tables. You can search different data with different queries then join the results in PHP or do some kind of JOIN. If you're not careful though you'll end up with something entirely inefficient.</p> <p>One more note - this should already match partial words as you have it - the %'s around your search term in the LIKE clause means 'any characters in this position' </p> <p>To search more fields in your restaurant, you could start with the following (if you have a slogan for instance):</p> <pre><code>$result = mysql_query("SELECT * FROM `restaurants` WHERE `restaurant` LIKE '%{$_GET['searchbox']}%' OR `slogan` LIKE '%{$_GET['searchbox']}%'"); </code></pre> <p><strong>You should not be injecting the user input directly into the SQL though, it leaves you open to attack!</strong></p> <p>To search more fields in other tables using a JOIN, you could start with the following (if you have a food table for instance):</p> <pre><code>$result = mysql_query("SELECT `restaurants`.* FROM `restaurants` LEFT JOIN `food` ON `food`.`restaurant_id` = `restaurant`.`id` WHERE `restaurant` LIKE '%{$_GET['searchbox']}%' OR `food` LIKE '%{$_GET['searchbox']}%'"); </code></pre> <p>You can look at these two pages if you need help with what I've just given you:</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/select.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/select.html</a></p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/join.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/join.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload