使用PHP的动态复选框.建立一个数组? [英] Dynamic Checkbox with PHP. Build an array?

查看:80
本文介绍了使用PHP的动态复选框.建立一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表,其中的值是从SQL表中检索的.

I have a list of checkboxes, with values retrieved from a SQL table.

$sql = "SELECT Name FROM APKs";
$resultado = mysql_query($sql) or die ("problema-- ".mysql_error());
$numero = 0;

print "<FORM NAME=\"form1\" METHOD=\"POST\" ACTION=\"index.php\">";
while($registo = mysql_fetch_array($resultado))
{
    $name = $registo['Name'];
    print "<Input type='Checkbox' Name='.$name.'>$name</br>";
    $nomes[numero] = $name;
    $numero++;
}




我只想保存所有名称选择.我认为最好的存储方式是使用数组,问题在于POST丢失了数据




What I just want to do is save all name choices. I think the best way is storing is using an array, the problem is the data is lost with the POST

if (isset($_POST['Submit1'])) {

    echo $nomes[0]; // I get here a null variable
}



如何有效解决此问题?

我认为最佳解决方案是使用



How can solve this problem in an efficient way?

I think the optimal solution is using

$name[numero] = $registo['Name'];
    print "<Input type='Checkbox' Name='.$name[numero].'>$name[numero]</br>";
    //$nomes[numero] = $name;
    $numero++;



然后



and then

echo "aqui" . $_POST[''$name''];



但是它不起作用,因为它没有保存$ name变量.我该怎么做?



but it''s not working because the $name variable it''s not saved. How can I accomplish that?

推荐答案

sql = " ;
sql = "SELECT Name FROM APKs";


结果 = mysql_query(
resultado = mysql_query(


sql)" 问题-" .mysql_error());
sql) or die ("problema-- ".mysql_error());


这篇关于使用PHP的动态复选框.建立一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆