Note that there are some explanatory texts on larger screens.

plurals
  1. POSecond MySQL Query not working
    primarykey
    data
    text
    <p>I have a webpage which sends a query to my MySQL database to retrieve information about my company's suppliers and echos the results (all fine so far). It then makes a second query to check if there are any known contacts associated with that supplier:</p> <pre><code>while ($row = mysqli_fetch_array($result)) { $contact = $row["contact"]; echo $row["name"] . "&lt;br&gt;" . $row["category"] . "&lt;br&gt;" . "Telephone: " . $row["telephone"] . "&lt;br&gt;" . "Fax: " . $row["fax"] . "&lt;br&gt;" . $row["email"] . "&lt;br&gt;" . $row["address"] . "&lt;br&gt;" . $row["postcode"] . "&lt;br&gt;&lt;br&gt;" . "Contact: " . $contact . "&lt;br&gt;"; $resultContact = mysqli_query($con,"SELECT * FROM contacts WHERE name = '$contact'"); while($rowContact = mysqli_fetch_array($resultContact)) { echo $rowContact["telephone"] . "&lt;br&gt;" . $rowContact["email"]; echo "&lt;br&gt;"; } } </code></pre> <p>(<code>$row</code> is from the first query and works.) However, <code>echo $rowContact["telephone"] . "&lt;br&gt;" . $rowContact["email"];</code> just prints whitespace.</p> <p>Thanks</p> <p><strong>EDIT:</strong> if I use a string literal in the Where clause, it works as it should. However, I used variables in exactly the same way as I am now in the first query and that works! I am confused :(</p> <p><strong>EDIT 2:</strong> the first query: <code>$result = mysqli_query($con,"SELECT * FROM suppliers WHERE LOWER(name) = LOWER('$searchText')");</code></p> <p><strong>EDIT 3:</strong> the result of doing <code>var_dump($resultContact);</code>: <code>object(mysqli_result)#3 (5) { ["current_field"]=&gt; int(0) ["field_count"]=&gt; int(4) ["lengths"]=&gt; NULL ["num_rows"]=&gt; int(0) ["type"]=&gt; int(0) }</code> I'm guessing this means that the query is coming back with the table ok, but the Where clause isn't comparing the contact name as I want it to...</p>
    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