0
我是编程的新手,我发现了一个工作代码,它允许我根据查询生成表,该查询还包含结果表的每行中的复选框。我如何从通过复选框选择的行中获取/检索值?使用SQL语句生成的复选框获取和操作表中的值
这里是产生该表的代码:
<?php
function SQLResultTable($Query)
{
$link = mysql_connect("localhost","root" , "") or die('Could not connect: ' . mysql_error()); //build MySQL Link
mysql_select_db("myDB") or die('Could not select database'); //select database
$Table = ""; //initialize table variable
$Table.= "<table border='1' style=\"border-collapse: collapse;\">"; //Open HTML Table
$Result = mysql_query($Query); //Execute the query
if(mysql_error())
{
$Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>";
}
else
{
//Header Row with Field Names
$NumFields = mysql_num_fields($Result);
$Table.= "<tr style=\"background-color: #000066; color: #FFFFFF;\">";
for ($i=0; $i < $NumFields; $i++)
{
$Table.= "<th>" . mysql_field_name($Result, $i) . "</th>";
if($i==$NumFields-1)
{
$Table.= "<th>  Select  </th>";
$Table.= "</tr>";
}
}
//Loop thru results
$RowCt = 0; //Row Counter
while($Row = mysql_fetch_assoc($Result))
{
//Alternate colors for rows
if($RowCt++ % 2 == 0) $Style = "background-color: #FFCCCC;";
else $Style = "background-color: #FFFFFF;";
$Table.= "<tr style=\"$Style\">";
//Loop thru each field
foreach($Row as $field => $value)
{
$Table.= "<td>      $value      </td>";
}
//$Table.= "<td><input type='checkbox'></td>";
$Table.= "<td><input type='checkbox'></td>";
$Table.= "</tr>";
}
}
$Table.= "</table>";
return $Table;
}
?>
谢谢!