Note that there are some explanatory texts on larger screens.

plurals
  1. POI want my search to only show results with matching field values. How is this done?
    text
    copied!<p>I want my search to only display results that match values in the same row.</p> <p>I have two search fields:</p> <p>'search' and 'search term'</p> <p>the field names in my database are</p> <p>name lastname email</p> <p>So for example:</p> <p>If i search </p> <p>'mike' in 'search' and 'smith' in 'search term' the only results I want to show are results that match 'mike smith' NOT showing results like 'mike harris'</p> <p>How is this achieved?</p> <p>Thanks!</p> <p>James</p> <pre><code> &lt;?php $conn = mysql_connect("", "", ""); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } $search = addcslashes($search,'%_'); $searchterm = addcslashes($searchterm,'%_'); $search = "%" . $_POST["search"] . "%"; $searchterm = "%" . $_POST["searchterm"] . "%"; if (!mysql_select_db("")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $search = $_POST['search']; $searchterm = $_POST['searchterm']; $sql = "SELECT name,lastname,email FROM test_mysql WHERE name LIKE '%". mysql_real_escape_string($search) ."%'"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if(empty($_GET['search'])){ // or whatever your field's name is echo 'no results'; }else{ performSearch(); // do what you're doing right now } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo '&lt;br&gt;&lt;br&gt;&lt;div class="data1"&gt;'; echo htmlentities($row["name"]); echo '&lt;/div&gt;&lt;br&gt;&lt;div class="data2"&gt;'; echo htmlentities($row["lastname"]); echo '&lt;/div&gt;&lt;br&gt;&lt;div class="data3"&gt;'; echo htmlentities($row["email"]); echo '&lt;/div&gt;'; } mysql_free_result($result); ?&gt; </code></pre>
 

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