Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL table comparison, build query and print filtered data into dropdown list
    primarykey
    data
    text
    <p>I have a stored value from one table called user_id. I have another table as such:</p> <p>client_projects:</p> <pre><code>+------------------+-------------+-------------+-------------+ | project_codename | client_id_1 | client_id_2 | client_id_3 | +------------------+-------------+-------------+-------------+ | Alpha | 1 | 2 | 3 | +------------------+-------------+-------------+-------------+ | Beta | 2 | 1 | 0 | +------------------+-------------+-------------+-------------+ | Gamma | 3 | 1 | 0 | +------------------+-------------+-------------+-------------+ </code></pre> <p>If the user_id = (client_id_1 or client_id_2 or client_id_3) then I want to print the corresponding project_codenames in a dropdown list. This is the php I have but is not returning the right results. I have marketed the areas I am unsure of.</p> <p>PHP(updated and solved):</p> <pre><code>&lt;?php $con = mysqli_connect("localhost","****","****","db") or die("Connection error: " . mysqli_error($con)); //stored sample value from another table $user_id = "1"; //Build query: Not sure if this is correct format $query = "SELECT * FROM client_projects WHERE client_id_1 = $user_id OR client_id_2 = $user_id OR client_id_3 = $user_id"; $result = mysqli_query($con, $query) or die("Query error: " . mysqli_error($con)); //Drop down list echo '&lt;select id="Projects" class="input"&gt;'; echo '&lt;option value="" selected="selected" disabled="disabled"&gt;Choose a Project...&lt;/option&gt;'; // Loop through the query results, outputing specific options one by one // Not sure of the loop for the options while ($row = mysqli_fetch_array($query)) { echo '&lt;option value="'.$row['project_codename'].'"&gt;'.$row['project_codename'].'&lt;/option&gt;'; } echo '&lt;/select&gt;'; mysqli_close($con); ?&gt; </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. 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