Php 以复选框形式显示表的内容

Php 以复选框形式显示表的内容,php,jquery,html,mysql,Php,Jquery,Html,Mysql,我的数据库中有一个名为“project\u name”的表,名为“encrypt\u decrypt”。该表仅包含一个名为“name”的列,其中包含不同的name值(例如:p1、p2、p3…)。我必须从我的数据库中检索这些值(p1、p2、p3..),并将其显示在注册表上,每个值都显示在另一个值的下方,并带有一个复选框,以便用户在注册时可以选择任何名称!如何在php中实现这一点 提前谢谢 <html> <body> <form name="reg" action="c

我的数据库中有一个名为“project\u name”的表,名为“encrypt\u decrypt”。该表仅包含一个名为“name”的列,其中包含不同的name值(例如:p1、p2、p3…)。我必须从我的数据库中检索这些值(p1、p2、p3..),并将其显示在注册表上,每个值都显示在另一个值的下方,并带有一个复选框,以便用户在注册时可以选择任何名称!如何在php中实现这一点

提前谢谢

<html>
<body>
<form name="reg" action="code_exec2.php" onsubmit="return validateForm()" method="post">
<table width="274" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td><div align="right" style="white-space:nowrap" >Please select the project:</td>
</tr>
<tr>
<td><div align="right"><input type="checkbox" name="project[]" ></div></td>
<td><?php
session_start();
include('connection2.php');
$row=mysql_query("select * from project_name");
$array= array();
$output = mysql_fetch_assoc($row);
 while($output){
     $array[] = $output;
    }
print_r($array);
?></td>
</tr>
<tr>
<td><div align="right"><input type="checkbox" name="Select all" 
 value="select all" onclick="toggle(this)"></div></td>
<td>Select all</td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>

请选择项目:
全选
试试这个

$result=mysql_query("select * from project_name");
$checkboxes=array();
while($r=mysql_fetch_assoc($result)){
    $checkboxes[]='<input type="checkbox" name="names[]" value="'.$r['name'].'">'.$r['name'].'<br />';
}

假设与db的连接正确,则需要更改显示结果的方式:

<?php
session_start();
include('connection2.php');
$row=mysql_query("select * from project_name");
$array= array();
 while($output = mysql_fetch_assoc($row)){ 
//now you have row with name, and you need to display each name with new tr:
?>        
<tr>
<td><div align="right"><input type="checkbox" name="project[]" value="<?php echo $output['name'] ?>"></div></td> 
<td><?php echo $output['name'] ?></td>
</tr>
 <?php   } // closing while loop
?>

请注意,我在复选框中添加了
value
——如果您想对选中的项目执行某些操作,您必须知道它是哪一个


记住,mysql_uu函数是不受欢迎的!你应该改用PDO或mysqli_uu,我试过了,我得到了:任何方法谢谢你的帮助:)


看起来您刚刚开始项目。我建议您使用
mysqli.*
PDO
,因为
mysql.*
已经过时,无法从PHP5.5中获得。
<?php
session_start();
include('connection2.php');
$row=mysql_query("select * from project_name");
$array= array();
 while($output = mysql_fetch_assoc($row)){ 
//now you have row with name, and you need to display each name with new tr:
?>        
<tr>
<td><div align="right"><input type="checkbox" name="project[]" value="<?php echo $output['name'] ?>"></div></td> 
<td><?php echo $output['name'] ?></td>
</tr>
 <?php   } // closing while loop
?>
<?php
include('connection.php');
$r=mysql_query("select distinct name from project_name");
$ProdArray=array();
while ($row = mysql_fetch_object($r)) {
array_push($ProdArray,$row->name);
}
foreach($ProdArray as $p) {
echo "<tr>";
echo "<td><div align='right'>";
echo "<input type='checkbox' name='project[]' value=" .$p. " />";
echo "</div></td>";
echo "<td>$p</td>";
echo "</tr>";