【发布时间】:2012-03-03 00:25:53
【问题描述】:
我正在尝试生成一个每行都有复选框的表格。我在下面找到了一个工作代码,用于根据查询结果生成表。是否可以在此处插入一个代码,该代码将提供一个额外的列,该列将在每一行中包含复选框?
<?php
function SQLResultTable($Query)
{
$link = mysql_connect("localhost","root" , "") or die('Could not connect: ' . mysql_error()); //build MySQL Link
mysql_select_db("dbName") 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>";
}
$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.= "</tr>";
}
}
$Table.= "</table>";
return $Table;
}
?>
【问题讨论】:
-
我建议你使用你最喜欢的搜索引擎并寻找 a) PHP 教程 b) HTML 教程 ...
标签: php html mysql checkbox html-table