gpt4 book ai didi

PHP变量变量困惑

转载 作者:行者123 更新时间:2023-11-29 13:01:08 25 4
gpt4 key购买 nike

我使用 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>";
}

最佳答案

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

 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] 现在可能指向不同的列。

关于PHP变量变量困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23324863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com