在HTML/PHP中创建复选框?
所以我有下面的代码 我的main.html表单允许我为pc输入一个值和一个价格,当我提交时,它会调用pcs.php脚本,该脚本显示给定值/价格下的所有pc 但是我想在脚本显示的信息旁边有一个复选框。即在HTML/PHP中创建复选框?,php,html,forms,Php,Html,Forms,所以我有下面的代码 我的main.html表单允许我为pc输入一个值和一个价格,当我提交时,它会调用pcs.php脚本,该脚本显示给定值/价格下的所有pc 但是我想在脚本显示的信息旁边有一个复选框。即 <br>alienware, 3000, gtx760 checkbox <br> asus rog, 2500, radeodhdxxxx checkbox <br> 等等 //main.html //pc.php //computer.txt文件 a
<br>alienware, 3000, gtx760 checkbox <br> asus rog, 2500, radeodhdxxxx checkbox <br>
等等
//main.html
//pc.php
//computer.txt文件
alienware, 3000, gtx760<br>
asus rog, 2500, radeonhdxxx<br>
alienware, 5000, gtx titan<br>
在pcs.php中,您只需修改for循环,使其看起来像:
// Create form
print '<form method="post" action="script_to_post_to.php">';
for ($mycount = 0; $mycount < count($myarray); $mycount++) {
$apc = $myarray[$mycount];
$price = getvalue($apc,1);
$part = explode(',', $apc);
if ($str < $dd) {
for($pcount = 0; $pcount<3; $pcount++) {
print $part[$pcount] ."<br>";
}
// Add checkbox and name with product type
print '<input type="checkbox" name="' . getvalue($apc, 2) . '" />';
print "<br>";
}
}
// Provide form submission button and close form element
print '<input type="submit" value="Submit" />';
print '</form>';
您将拥有一个表单,其中每个元素都有一个复选框,并且能够响应script\u to\u post\u to.php中的选中项列表。您能详细说明一下吗?您只是想在循环中添加echo吗?谢谢您的回答,但现在我有另一个问题。我想使复选框成为一个数组,然后当我调用脚本时,如果我想显示选中的元素,我会以不同的方式命名复选框,它可以工作,但如果我将复选框设置为数组,它就不能工作。
alienware, 3000, gtx760<br>
asus rog, 2500, radeonhdxxx<br>
alienware, 5000, gtx titan<br>
// Create form
print '<form method="post" action="script_to_post_to.php">';
for ($mycount = 0; $mycount < count($myarray); $mycount++) {
$apc = $myarray[$mycount];
$price = getvalue($apc,1);
$part = explode(',', $apc);
if ($str < $dd) {
for($pcount = 0; $pcount<3; $pcount++) {
print $part[$pcount] ."<br>";
}
// Add checkbox and name with product type
print '<input type="checkbox" name="' . getvalue($apc, 2) . '" />';
print "<br>";
}
}
// Provide form submission button and close form element
print '<input type="submit" value="Submit" />';
print '</form>';