drasebt1835 2019-06-17 10:54
浏览 46

从PHP和SQL加入多个表,并为每个循环返回一个字符串

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";
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类