我的mysql数据库有以下内容:
productid | productname | category
1 XYZ News
2 ZYX News
3 vcb Info
我想像这样按类别将它们显示在表组中
Category : News
xyz
zyx
Category : Info
vcb
Etc....
目前我正在使用
$sql="SELECT * FROM database Group By category";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {
echo "<table cellspacing='0' cellpadding='0'>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>catergory</th>
</tr>
</thead>";
$i = 0;
while($row = mysql_fetch_array($result))
{
if($i%2 == 0)
{
$class = 'even';
}
else
{
$class = 'odd';
}
{
echo "<tbody>";
echo "<tr class='$class'>";
echo "<td>" . $row['productid'] . "</td>";
echo "<td style='font-weight: bold; text-align: center;'>" . $row['productname '] . "</td>";
echo "<td style='font-weight: bold; text-align: center;'>" . $row['category '] . "</td>";
echo "</tr>";
}
$i++;
}
echo "</tbody>";
echo "</table>";
} else {
echo "";
}