用PHP实现动态表列
我想使用一个MySQL查询生成一个包含两个动态列的表。我可以创建第一行列,但第二行只是空白。有什么想法吗?这是我目前的代码:用PHP实现动态表列,php,mysql,sql,Php,Mysql,Sql,我想使用一个MySQL查询生成一个包含两个动态列的表。我可以创建第一行列,但第二行只是空白。有什么想法吗?这是我目前的代码: <?php $query_dates ="SELECT uploadedby, count(item) as item, date_format(uploaddate, '%m-%d-%y') as date FROM `imsexport` WHERE uploadedby='Gerry Dellosa' and uploaddate between '2012-
<?php
$query_dates ="SELECT uploadedby, count(item) as item, date_format(uploaddate, '%m-%d-%y') as date FROM `imsexport` WHERE uploadedby='Gerry Dellosa' and uploaddate between '2012-12-25' and '2013-01-15' GROUP BY date ORDER BY uploaddate ASC";
$result = mysql_query($query_dates,$prepress) or die(mysql_error());
$row_dates = mysql_fetch_assoc($result);
?>
<html>
<head>
</head>
<body>
<table width="200" border="1">
<tr>
<td>NAME</td>
<?php do{?>
<td><?php echo $row_dates['date']?></td>
<?php } while ($row_dates = mysql_fetch_assoc($result)); ?>
</tr>
<tr>//This is the second row set of dynamic columns
<?php do{?>
<td><?php echo $row_dates['date']?></td>
<?php } while ($row_dates = mysql_fetch_assoc($result)); ?>
</tr>
</table>
</body>
</html>
在第二行之前重置提取循环
mysql_data_seek($result,0);
在第一个do while循环之后,您已经迭代了整个结果集,因此第二个so while循环不包含任何内容。确实要两个相等的列吗?或者你只想在两列中显示你的数据?@YourCommonSense:对不起,这是一个打字错误。第二组列实际上用于$row_日期['item'];很好,谢谢。现在,如果没有WHERE uploadedby='Gerry Dellosa'条件,并且我希望uploadedby在名称列下垂直回显,同时保留每个uploadedby值的水平数据值,该怎么办呢。。foreach(..){..$rec[name]$rec[date]}
mysql_data_seek($result,0);