douejuan9162 2014-04-22 13:48
浏览 18
已采纳

变量不通过

So when I click on a radio tick I want the specific value to be sent to the file 'testview.php' and then echo it out. However, I have a while statement/loop that grabs out all the data in the table 'album' and the rows would include the following: path1, path2, path3 etc but when I click on the path1 radio tick it displays the necessary information but when I click path2 it shows the same information from path1. Below is the codes and can someone please help?

Thank you.

<div class="albumwrapper">
<form action="testview.php" method="post">
        <table> 

<?php
$select_album_names = "SELECT * FROM albums WHERE user_id = '$session_user_id'";
$album_names = mysql_query($select_album_names);
while($display_album_names = mysql_fetch_array($album_names))
  {
    echo "<tr><td>".'<input type="radio" name="field" id="radio1" value="'.$display_album_names['path'].'" onclick="this.form.submit();">'.'<label for="radio1">'.$display_album_names['name'].'</label>'."</td></tr>";
  }

?>
        </table>
    </form>
</div>
<div id='imagedest'>
</div>




//testview.php
<?php
echo $_POST['field'];

?>
  • 写回答

1条回答 默认 最新

  • dr5648 2014-04-22 13:58
    关注

    All the radio buttons have the same ID :) Try something like this:

    <?php
    $i = 0;
    $select_album_names = "SELECT * FROM albums WHERE user_id = '$session_user_id'";
    $album_names = mysql_query($select_album_names);
    while($display_album_names = mysql_fetch_array($album_names))
      {
        echo "<tr><td>".'<input type="radio" name="field" id="radio'.$i.'" value="'.$display_album_names['path'].'" onclick="this.form.submit();">'.'<label for="radio'.$i.'">'.$display_album_names['name'].'</label>'."</td></tr>";
    $i++;
      }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程