变量不通过

时间:2014-04-22 13:48:24

标签: php html mysql

因此,当我点击收音机时,我希望将特定值发送到文件' testview.php'然后回应它。但是,我有一个while语句/循环来抓取表格中的所有数据' album'行将包括以下内容:path1,path2,path3等,但是当我单击path1单选按钮时,它会显示必要的信息,但是当我单击path2时,它会显示来自path1的相同信息。以下是代码,有人可以帮忙吗?

谢谢。

<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 个答案:

答案 0 :(得分:1)

所有单选按钮都具有相同的ID :) 尝试这样的事情:

<?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++;
  }

?>