2013-01-18 4 views
0

하나의 MySQL 쿼리를 사용하여 2 개의 동적 열이있는 테이블을 만들고 싶습니다. 첫 번째 행을 만들었지 만 두 번째 행은 비어 있습니다. 어떤 아이디어? 두 번째 루프는 아무것도 포함하지 않도록하면서 그렇게 결과 세트 전체에 걸쳐 반복 한 루프 동안PHP가있는 동적 테이블 열

<?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

전에 루프를 가져 오기 : 여기에 내 현재 코드입니다 . – shannonman

+0

2 개의 동일한 열을 원하십니까? 아니면 데이터를 2 열로 표시하고 싶습니까? –

+0

@YourCommonSense : 미안하지만 오타였습니다. 두 번째 열 집합은 실제로 $ row_dates [ 'item']에 대한 것입니다. – rain

답변

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> 
+0

일해 줘서 고마워. 이제는 'uploadedby ='Gerry Dellosa '조건이 없으면 업로드 된 각 값에 대한 가로 데이터 값을 그대로 유지하면서 Uploadedby를 Name 열 아래에 세로로 표시하려고합니다. – rain

+0

.. .. ..의 foreach (...) {... ..}' – vectorialpx

-1

리셋이 첫 번째 할 일 후 두 번째 행

mysql_data_seek($result,0); 
이름 날짜 '처럼
$ 촬영 [이름] $ REC [날짜] 광고 아닌 열의 세트의 foreach