因此,当我单击单选按钮时,我希望将特定值发送到文件“ 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'];

?>

最佳答案

所有单选按钮都具有相同的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++;
  }

?>

关于php - 变量未通过,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23221476/

10-09 01:00