2012-02-17 19 views
0

我的目標是從mysql中取出數據並將其打印在html表格中。 asumming 1,2,3 ... 8是數據在一張不錯的html表格中打印php結果

<table style="width: 100%"> 
<tr> 
<td>1</td> 
<td>2</td> 
<td>3</td> 
<td>4</td> 
</tr> 
<tr> 
<td>5</td> 
<td>6</td> 
<td>7</td> 
<td>8</td> 
</tr> 
</table> 

這是我到目前爲止的代碼,但這隻會打印出列但沒有行。 plz幫助。謝謝

<table style="width: 100%; color:aqua"> 
<?php    
$showFoto = getFoto(); 
echo '<tr>'; 
foreach($showFoto as $Foto){ 
echo '<td class="afs"><img alt="" src="img/'.$Foto['img'].'.'.$Foto['ext'].'"><br>'.$Foto['about'].'</td>'; 
} 
echo '</tr>'; 
?> 
</table> 
+0

你需要用你的就像你與你的​​周圍做另一個循環。 – Aaron 2012-02-17 20:57:32

+0

http://php.net/manual/fr/function.print-r.php如果你下了print_nice函數。我用它來處理類似的情況。 – 2012-02-17 20:57:57

+0

'echo'';'和'echo'';'在任何循環結構之外。 – 2012-02-17 20:58:46

回答

1

TRY

<table width ="100%" style="color:aqua" cellpadding="2" cellspacing="2"> 
    <tr> 
<?php    
    $showFoto = getFoto(); 
    $i=0; 
    foreach($showFoto as $Foto){ 
     ++$i; 
     echo ($i%4==0) ? '</tr><tr>' :''; 
     echo '<td class="afs"> 
      <img alt="" src="img/'.$Foto['img'].'.'.$Foto['ext'].'">'.$Foto['about']. 
      '</td>';   
    } 
    ?> 
    </tr> 
</table> 
+1

感謝這個作品。對不起,我花了很長時間迴應..被抓住了.. – user618879 2012-02-18 00:55:33