I have a multiple select form like so:
<form name="form" action="result2.php" method="post">
<label>Type of Resource</label>
<select name="resources[]" multiple>
<option>Charitable Organization</option>
<option>Women-Only Shelter</option>
<option>Men-Only Shelter</option>
<option>Family Shelter</option>
<option>Youth Shelter</option>
<option>Emergency Shelter</option>
</select>
<input type="submit" value="Submit">
</form>
The user will be able to select multiple options and all the shelter in my database under each selected categories will be displayed. Here is my php code:
$value_4 = $_POST["resources"];
if($value_4){
foreach ($value_4 as $v){
$result = mysqli_query($dbc, "SELECT DISTINCT shelter_name, type_name
FROM shelter s
INNER JOIN shelter_type st on s.shelter_id = st.shelter_id
INNER JOIN s_type stt on st.type_id = stt.type_id
WHERE type_name = '$v'");
}
}
echo"<table border='1'>";
echo"<tr><td>Shelter</td><td>Type</td></tr>";
while ($row = mysqli_fetch_assoc($result)){
echo"<tr><td>{$row['shelter_name']}</td><td>{$row['type_name']}</td></tr>";}
echo"</table>";
Currently, I can only get the LAST selected option to display. How can I change my php code that ALL the data under each selected option get displayed? Thanks.