2011-11-13 6 views
0

複数の行を印刷し、各行に複数の数値を入力する必要があります。td ... 3の後にtrを追加する必要があります。phpとsqlの値で表を印刷する

echo '<table>'; 
    for($counter=0; $counter <= $row2 = mysql_num_rows($result2);counter++) { 
    print("<tr>"); 

    while($row2 = mysql_fetch_array($result2)) { 
     $_name = $row2["_name"]; 
     $_image = $row2["_image"]; 

     print("<td valign='top' width='230px' height='148px'>"); 
     print("<p class='p_imageStyle'>$_name</p>"); 
     print("<img class='custom' alt='' src='$_image' />"); 
     print("</td>"); 
    } 

    print("</tr>"); 
    } 

    echo '</table> '; 
+0

(http://www.hotdesign.com/seybold/everything.html)[それを行う]、[現代の何か](http://www.google.coをしないでください。 uk/search?sourceid = chrome&ie = UTF-8&q =写真+グリッド+ css) – Quentin

+0

誰かが回答を投稿してくれました。あなたの回答を認められるように再投稿してください...カウンターを増やすために欠けていたのは唯一のことです。 – user710502

答えて

2
echo '<table>'; 
    $counter=1; 
    while($row2 = mysql_fetch_array($result2)) { 
    if($counter%3==1) 
    print("<tr>"); 
    $_name = $row2["_name"]; 
    $_image = $row2["_image"]; 

    print("<td valign='top' width='230px' height='148px'>"); 
    print("<p class='p_imageStyle'>$_name</p>"); 
    print("<img class='custom' alt='' src='$_image' />"); 
    print("</td>"); 
    if($counter%3==0) 
    print("</tr>"); 
    $counter++; 
} 
$counter--; 
$rem=3-$counter%3; //modifed as per alartur 
for($i=0;$i<$rem;$i++) 
{ 
    echo "<td></td> //print remaining td 
} 
if($rem!=0) 
echo "</tr>"; //close tr if not closed 
echo '</table> '; 
+0

残りのtdsの数が間違っています(rem!= 0の場合は、(3-rem)までカウントアップする必要があります)、残りの部分はOKです。 – alexpirine