我已经查看了类似的问题和解决方案,但不知何故只有一半的方式帮助我解决我的问题。我正在尝试创建一个表单来检查来自MySQL数据库的多个记录,并将检查的记录显示到另一个页面。不知何故,我设法用复选框做页面,但我不知道如何显示检查的记录。它只能显示记录的第一行或所有记录,无论选中哪个框。
这是复选框页
$columns = count($fieldarray);
//run the query
$result = mysql_query(
"SELECT * FROM request_item
ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error());
$row = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
{
$rows[] = $row['IllNo'];
}
foreach($rows as $value);
echo "";
echo " ";
echo $row['IllNo'];
echo "";
}
echo "";
?>
这是选中的显示记录
$columns = count($fieldarray);
//run the query
$result = mysql_query(
"SELECT * FROM request_item
ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error());
$row = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$rows[]=$row['IllNo'];
foreach($rows as $value);
if ($rows= 'checked') {
echo "";
echo $value;
}
欢迎任何帮助。谢谢。
答案 0 :(得分:1)
这个脚本实际上存在很多问题,包括语法错误,调用错误的变量名,表单没有打开它应该在你已经拥有之后调用PHP等等......
为了得到一个好的答案,你应该分享$ row ['IllNo']应该等于表明是否应该检查的内容。
我重新格式化了一下,这可能会给你一个良好的开端。
<form NAME ="form1" METHOD ="POST" ACTION ="dari.php">
<table>
<?php
$columns = count($fieldarray);
//run the query
$result = mysql_query("SELECT * FROM request_item ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error()) ;
$row = mysql_num_rows($result);
while($row=mysql_fetch_array($result)) {
echo "<tr><td>";
echo "<Input type = 'Checkbox' Name ='ch1' value ='ch1'";
// check checked if it is. this will be checked if $row['IllNo'] has a value
// if there were a condition to make it checked, you would put the condition
// before the ?
echo $row['IllNo'] ? ' checked' : '';
echo ' />';
echo $row['IllNo'];
echo "</td></tr>";
}
?>
</table>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Choose your books">
</FORM>