我想使用一个MySQL查询创建一个包含2个动态列的表。我能够创建第一行列,但第二行只是空白。有任何想法吗?这是我目前的代码:
<?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>
答案 0 :(得分:3)
<?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());
while($row_dates = mysql_fetch_assoc($result)) {
$record[] = $row_dates;
}
?>
<html>
<head>
</head>
<body>
<table width="200" border="1">
<tr>
<td>NAME</td>
<?php foreach($record as $rec ) { ?>
<td><?php echo $rec['date'] ?></td>
<?php } ?>
</tr>
<tr>//This is the second row set of dynamic columns
<?php foreach($record as $rec ) { ?>
<td><?php echo $rec['date'] ?></td>
<?php } ?>
</tr>
</table>
</body>
</html>
答案 1 :(得分:-1)
在第二行之前重置提取循环
mysql_data_seek($result,0);