Php 在干净专业的表格报告中显示mysql返回
这是我本周的第二个问题(到目前为止)。我的第一个解决方案很成功,所以我认为这一个也会很幸运。 我想通过以下方式布局/设计返回我的查询:Php 在干净专业的表格报告中显示mysql返回,php,grouping,tabular-form,Php,Grouping,Tabular Form,这是我本周的第二个问题(到目前为止)。我的第一个解决方案很成功,所以我认为这一个也会很幸运。 我想通过以下方式布局/设计返回我的查询: date 1 | id | time | updated by | Status Update | 1 | 04:06 | user1 | this is a remark | 2
date 1 | id | time | updated by | Status Update
| 1 | 04:06 | user1 | this is a remark
| 2 | 05:05 | user2 | this is again a remark
| 3 | 05:08 | user1 | this is another remark
| 4 | 07:09 | user3 | and this one also
date 2 | id | time | updated by | Status Update
| 5 | 04:06 | user3 | this is a remark for day 2
| 6 | 05:05 | user3 | this is again a remark for day 2
date 3 | id | time | updated by | Status Update
| 7 | 04:06 | user1 | this is a remark
| 8 | 05:05 | user2 | this is again a remark
| 9 | 05:08 | user2 | this is another remark
| 10 | 07:09 | user3 | and this one also
这是我的php代码
mysql declaration here
{
echo "<table border='0' align=center class='tablefont'>
<tr class='colheadbg'>
<th>Date</th>
<th>ID</th>
<th>Time</th>
<th>Updated by</th>
<th>Status Update</th>
</tr>";
while($info = mysql_fetch_array( $data ))
{
$id_num=$id_num + 1;
echo "<tr>
<td>".$info['date']."</td>
<td>$id_num</td>
<td>".$info['time']."</td>
<td>".$info['user']."</td>
<td>".$info['remarks']."</td>";
echo "</tr>";
}
echo "</table>";
}
?>
mysql声明在这里
{
回声“
日期
身份证件
时间
更新人
状态更新
";
而($info=mysql\u fetch\u数组($data))
{
$id_num=$id_num+1;
回声“
“$info['date']”
$id_num
“$info['time']”
“$info['user']”
“$info[‘备注’]”;
回声“;
}
回声“;
}
?>
到目前为止,这输出了一个表格形式的报告,这不是我真正想要的。我听说过这个“组”,但我真的需要有一个好的开始想法来启动它。在函数中创建一个
$date
变量,然后在每次迭代中将其与当前行的日期进行比较,如下所示:
var $date = "";
while($info = mysql_fetch_array( $data )) {
$id_num=$id_num + 1;
echo "<tr>";
if ($date==$info['date']) {
echo "<td>".$info['date']."</td>
<td>$id_num</td>
<td>".$info['time']."</td>
<td>".$info['user']."</td>
<td>".$info['remarks']."</td>";
}
else {
$date=$info['date']; //set it for the new date first
//do your row magic
}
echo "</tr>";
}
var$date=”“;
而($info=mysql\u fetch\u数组($data)){
$id_num=$id_num+1;
回声“;
如果($date==$info['date'])){
回显“.$info['date']”
$id_num
“$info['time']”
“$info['user']”
“$info[‘备注’]”;
}
否则{
$date=$info['date'];//首先为新日期设置它
//你的划船变魔术了吗
}
回声“;
}
从OPs屏幕截图更新
var$date=”“;
而($info=mysql\u fetch\u数组($data)){
$id_num++;
回声“;
如果($date==$info['date'])){
回声“/**无**/”;
回显“$id\u num
{$info['time']}
{$info['user']}
{$info['comments']}”;
}
否则{
$date=$info['date'];//首先为新日期设置它
回音“$日期
$id_num
{$info['time']}
{$info['user']}
{$info['comments']}”;
}
回声“;
}
根据您在屏幕截图中显示的内容,它看起来可能会解决此问题。在函数中创建一个
$date
变量,然后在每次迭代中将其与当前行的日期进行比较,如下所示:
var $date = "";
while($info = mysql_fetch_array( $data )) {
$id_num=$id_num + 1;
echo "<tr>";
if ($date==$info['date']) {
echo "<td>".$info['date']."</td>
<td>$id_num</td>
<td>".$info['time']."</td>
<td>".$info['user']."</td>
<td>".$info['remarks']."</td>";
}
else {
$date=$info['date']; //set it for the new date first
//do your row magic
}
echo "</tr>";
}
var$date=”“;
而($info=mysql\u fetch\u数组($data)){
$id_num=$id_num+1;
回声“;
如果($date==$info['date'])){
回显“.$info['date']”
$id_num
“$info['time']”
“$info['user']”
“$info[‘备注’]”;
}
否则{
$date=$info['date'];//首先为新日期设置它
//你的划船变魔术了吗
}
回声“;
}
从OPs屏幕截图更新
var$date=”“;
而($info=mysql\u fetch\u数组($data)){
$id_num++;
回声“;
如果($date==$info['date'])){
回声“/**无**/”;
回显“$id\u num
{$info['time']}
{$info['user']}
{$info['comments']}”;
}
否则{
$date=$info['date'];//首先为新日期设置它
回音“$日期
$id_num
{$info['time']}
{$info['user']}
{$info['comments']}”;
}
回声“;
}
根据您在屏幕截图中显示的内容,这可能会解决问题。感谢Christopher的及时回复。您的建议确实有效,但输出表有一个小问题。日期有点延迟或向下移动了一行。我把截屏保存在这里:谢谢。试试那个@Macoy。应该生产出你想要的。它成功了!!!!!哇!谢谢你@Christopher。。。现在我可以睡个好觉了…@Macoy,请不要取消选择答案。哦。。。很抱歉只是太激动了!谢谢克里斯托弗的及时回复。您的建议确实有效,但输出表有一个小问题。日期有点延迟或向下移动了一行。我把截屏保存在这里:谢谢。试试那个@Macoy。应该生产出你想要的。它成功了!!!!!哇!谢谢你@Christopher。。。现在我可以睡个好觉了…@Macoy,请不要取消选择答案。哦。。。很抱歉只是太激动了!