0

我正在使用while循环并mysql_fetch_array在数据库的页面上显示信息。如何为页面上回显的某些单选按钮元素提供变量名称,然后在$_POST提交表单时将这些变量名称用于单选按钮作为变量?

这是代码:

session_start();
include 'acdb.php';

$prodid = $_SESSION['prodid'];

$e = "SELECT * FROM Images WHERE product_id=$prodid AND active='yes'";
$e_result = mysql_query($e,$connection) or die ('Could not get the list of all Images for this Product and Service');
$amount = mysql_num_rows($e_result);

while ($e_data = mysql_fetch_array($e_result)) {
    echo "<img src='images/thumbnails/" .$e_data[1]. "' border='0'>";
    echo "<label class='sel-photo'>DISPLAY PICTURE:</label> <input type='radio' name='{radio" .$e_data[0]. "}' value='1'>";
    echo "<br>";
    echo "<label class='sel-photo'>DO NOT DISPLAY PICTURE:</label> <input type='radio' name='{radio" .$e_data[0]. "}' value='0' checked>";
}                   
4

1 回答 1

1

这样做你会得到你想要的结果

 echo "<label class='sel-photo'>DISPLAY PICTURE:</label> <input type='radio' name='radio" .$e_data[0]. "' value='1'>";

所以假设 $e_data[0] = 'xxx' 你会得到 html

name='radioxxx'

PS。它最好,尤其是在使用SELECT *表单时$e_data['fieldname']。这是因为使用*. 如果您/其他人决定在以后重新组织表格列,它们将以不同的顺序返回,并且$e_data[0]现在可能指向不同的列。

于 2014-04-27T15:37:11.317 回答