Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to search based on two cell values
    primarykey
    data
    text
    <p>I am using a search box to find entries in my database. One column contains the title / name of the thing being looked for. Then I have a second column which gives a short description as applicable (few words usually)</p> <p>I am trying to search (with the search box) to match either one or even both of the cells combined. Is that possible, and if yes, how?</p> <p>You can see my code below which kind of shows what I try to achieve, but in any case, let me illustrate this a bit:</p> <pre><code>Example: Database.title = "towel" Database.description = "red, small" Now, if I type into my search box "tow%red" I want to find the item. </code></pre> <p>It obviously does not find it, because the title does not contain "red". But if I search for "towel" only, it might show me different items based on different sizes, colors, or other attributes and the list becomes too long. Of course I also want to be able to simply search for "%red%small% and still be able to find it, or just search for "towel".</p> <p>Here is my php code that does the search:</p> <pre><code>if ( !isset($_REQUEST['term']) ) { exit; } $search = mysql_real_escape_string($_REQUEST['term']); $queryString = "SELECT * FROM items WHERE title+description LIKE '%{$search}%'"; $query = mysql_query($queryString); $data = array(); if ( $query &amp;&amp; mysql_num_rows($query) ) { while( $row = mysql_fetch_array($query, MYSQL_ASSOC) ) { $label = $row['title']; if ($row['description']) { $label .= ' &amp;mdash; '. $row['description']; } $data[] = array( 'label' =&gt; $label, 'value' =&gt; $row['code'] ); } } echo json_encode($data); flush(); </code></pre> <p>I know the above is not going to work, I just put it that way to make clear what I want. The working code contains this line instead:</p> <pre><code>$queryString = "SELECT * FROM items WHERE title LIKE '%{$search}%'"; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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