dongzhuner6981 2010-07-18 23:52
浏览 14
已采纳

在一段时间的循环混乱!

I have spent quite some time making a function and the last 15-20 minutes trying to figure this out. I need help!

I am selecting multiple rows from the database and then running them in a while loop.

They are available on a dropdown menu.

<form method="POST" action="adminprocess.php">
  <fieldset>
    <p>
      <label class="left2">League:</label>
      <select name="league" class="combo">
      <?php 
        $q = $database->selectAllLeagues();
        while($row=mysql_fetch_assoc($q))
        {
          $theid = $row['id'];
          extract($row);
          ?>
          <option value="<? echo $theid; ?>"> 
            <? echo $format.'_'.$game.'_'.$name.'_Season '.$season;?> 
          </option>
          <?
        }
      ?>
      </select>
    </p>
    <p>
      <input type="hidden" name="replaceleague" />
      <input type="hidden" name="format" value="<? echo $format; ?>" />
      <input type="hidden" name="game" value="<? echo $game; ?>" />
      <input type="hidden" name="name" value="<? echo $name; ?>" />
      <input type="hidden" name="season" value="<? echo $season; ?>" />
      <input type='submit' class="button" value='Select league' />
    </p>
  </fieldset>
</form>

$theid seems to be working fine dependning on which row i select on the dropdown menu. However, I cant get the values below in the hidden inputs to pass through the correct values from the row selected in the dropdown box.

It seems to always pass through the 4 variables from the first row of the database.

So basically, I need it to select the right row and use that data. What am i doing wrong!!! Thanks for reading!

  • 写回答

2条回答 默认 最新

  • doukuai3822 2010-07-19 00:00
    关注
    1. Your hidden fields are initialized outside the loop, so they'll use the values that were left over from the last iteration of the while loop. (i.e. the last fetched row)

    2. Why do you actually need the hidden fields in the first place? When you submit the form, the league field will contain the ID of the row selected in the drop-down box. Using the ID, you can fetch the other fields from the database when processing the form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序