I am trying to get a table to generate based on the sql query in this page, and I have it working with one item in the dropdown menu.
However if I select two, nothing happens, probably because I am either storing the variable incorrectly in $forum or I am accessing it incorrectly in the if $row statement further down.
Please help me understand what to do.
Thanks!
<select name="forums" multiple>
<option disabled selected value> -- Select a forum -- </option>
<?php
$con = mysqli_connect("host","user","pass","db");
if (!$con) {
die('Connection failed: ' . mysqli_connect_error() . '<br>');
}
$productName='
SELECT p.name
FROM product as p
JOIN ownedproducts as o
on o.productID = p.productID
WHERE usersID = 2;
';
$result=mysqli_query($con, $productName);
while ($row = mysqli_fetch_assoc($result)) {
unset($id);
$id = $row['name'];
echo '<option value="'.$id.'">'.$id.'</option>';
}
if(isset($_GET["forums"])){
$forum=$_GET["forums"];
echo "selected forum => ".$forum;
}
?>
</select>
<input type="submit" class = "submit" value="submit" onclick="this.form.submit();" />
</form>
</div>
<hr>
<table class = "table">
<tr id=table-row>
<th id=table-header>Name</th>
<th id=table-header>Company</th>
<th id=table-header>Type</th>
</tr>
<?php
while ($row = $query1->fetch())
{
if ($row['name']== $forum) {
echo "<tr id=" . $row['productID'] . ">";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
}
?>```