I'm trying to build a workout system. The user selects a piece of equipment from a multiselect dropdown. Each piece of equipment has associated exercises. When a piece of equipment is selected, I need to select a button which runs a query and joins the tables to get an associated exercise and display these exercises in a random order.
The below query gets the selected equipment from the DB from a selected multiselect.
<form method="post">
<select name="selected[]" class="selectpicker" multiple data-live-search="true">
<option><?php echo $equipment; ?></option>
</select>
<br/>
<br/>
<button type="submit" name="submit" class="btn btn-outline-success btn-sm"> Confirm </button>
</form>
<?php
//check if form is submitted successfully
if(isset($_POST["submit"]))
{
//check if any option is selected
if(isset($_POST["selected"]))
{
// retrive each selected option
foreach ($_POST['selected'] as $selected)
print "You selected $selected<br/>";
print "Select the Shuffle button to get workout";
}
else
echo "Select an option first";
}
I have tried the below to join the tables and display an exercise
// retrieve each selected option
foreach ($_POST['selected'] as $selected)
"GET ExerciseID FROM `ExerEquip`
JOIN Exercise
ON Exercise.ExerciseID = ExerEquip.ExerciseID
WHERE `EquipmentName`= selected
order by rand()
LIMIT 1;";
print "You selected $selected<br/>";
print "Select the Shuffle button to get workout";