Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To do what you would like, you might want to try a <code>UNION</code> statement. A union statement will take results from one query and add it into the results from another query while preserving the order (in my example, results having the email will come first, followed by fornavn, followed by efternavn). Doing it this way will also eliminate your <code>AND/OR</code> logic that might be preventing search results from appearing.</p> <pre><code>SELECT *, kunde.id as kundeid FROM kunde INNER JOIN $bartype ON ($bartype.brugerid = kunde.id) WHERE $bartype.barid ='$barid[Barid]' AND email LIKE '%$keyword%' UNION ALL SELECT *, kunde.id as kundeid FROM kunde INNER JOIN $bartype ON ($bartype.brugerid = kunde.id) WHERE $bartype.barid ='$barid[Barid]' AND fornavn LIKE '%$keyword%' UNION ALL SELECT *, kunde.id as kundeid FROM kunde INNER JOIN $bartype ON ($bartype.brugerid = kunde.id) WHERE $bartype.barid ='$barid[Barid]' AND efternavn LIKE '%$keyword%' </code></pre> <p>On a side note, dynamic SQL like this is ripe for SQL injection. May I suggest you to look into <a href="http://php.net/manual/en/book.pdo.php" rel="nofollow">PHP PDO</a></p> <p><strong>UPDATE</strong></p> <p>After your comment, here is an updated query that may be able to perform both searches at once for you:</p> <pre><code>SELECT *, kunde.id as kundeid FROM kunde INNER JOIN $bartype ON ($bartype.brugerid = kunde.id) WHERE $bartype.barid ='$barid[Barid]' AND email LIKE '%$keyword%' UNION ALL SELECT *, kunde.id as kundeid FROM kunde INNER JOIN $bartype ON ($bartype.brugerid = kunde.id) WHERE $bartype.barid ='$barid[Barid]' AND fornavn + ' ' + efternavn LIKE '%$keyword%' </code></pre>
    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.
 

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