Note that there are some explanatory texts on larger screens.

plurals
  1. POConditions in Mysql query does not work
    primarykey
    data
    text
    <p>I have problems while creating a query for my Live search engine.</p> <p>The structure of the table is like:</p> <pre><code> street | zipcode | city col1.: streetname | 12345 | london col1.: otherstreet | 12345 | london </code></pre> <p>My problem is the following:</p> <p>When I will search for <code>12345 london streetname</code> I will get a wrong result for the queries that are quiet simple. When i will echo out the query I get this as a result:</p> <pre><code>`zipcode` LIKE '12345%' AND `city` LIKE 'london%' OR `street` LIKE 'london%' AND `city` LIKE 'streetname%' OR `street` LIKE 'streetname%' </code></pre> <p>I fetch the results by using:</p> <pre><code>$where = ... $query = $db-&gt;query("SELECT * FROM table WHERE $where"); $result = $query-&gt;num_rows; if ($result !== 0 ){ echo $result; while ($row = $query-&gt;fetch_assoc()) { echo $row["zipcode"], ' ', $row["city"]'; } } </code></pre> <p>and the curious about that is that I receive a correct result when I change the order of input into:</p> <p><code>streetname 12345 london</code></p> <p>then I get:</p> <pre><code>`city` LIKE 'streetname%' OR `street` LIKE 'streetname%' AND `city` LIKE 'london%' OR `street` LIKE 'london%' AND `zipcode` LIKE '12345%' </code></pre> <p>it seems like there is also a problem with the last <code>AND</code>condition. When I will change the zipcode in that example:</p> <p><code>streetname london 12345</code></p> <p>it does not matter and even with wrong zipcode I get this result.</p> <p>So if someone can give me hints to solve this issue I really would apreciate.</p> <p>Thanks alot.</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. 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