0
echo "<table class='listing'>"; 
$i=0;
for ($i=1;$i<=$num;$i++) {
       while( $row = $rs->fetch_assoc() ) {
        echo "<tr>";
        echo "<td><a href='?p=view_org&oid={$row['org_id']}'>{$row['org_name']}<br /><img src='{$row['org_logo']}' width='120px' /></a></td>";
        echo "</tr>";  
    }
echo "</table>";  

結果は1つのtrとtdで生成されるため、画像はリストとして表示されます...このループを処理してtdのアイテムを4つだけにしてから、別の4つのアイテムで新しいtrを開始するアイデアを誰かが与えることができますか?

4

3 に答える 3

5
echo "<table class='listing'><tr>";
$i = 0;
while( $row = $rs->fetch_assoc() ) {
    echo "<td><a href='?p=view_org&oid={$row['org_id']}'>{$row['org_name']}<br /><img src='{$row['org_logo']}' width='120px' /></a></td>";
    $i++;
    if($i%4==0){
        echo "</tr><tr>";
    }
}
echo "</tr></table>";  
于 2012-09-21T04:34:36.693 に答える
2

このようにしてみてください

echo "<table class='listing'>"; 
$i=0;
echo "<tr>";   
     while( $row = $rs->fetch_assoc() ) {         
     echo "<td><a href='?p=view_org&oid={$row['org_id']}'>{$row['org_name']}<br /><img src='{$row['org_logo']}' width='120px' /></a></td>";
     $i++; 
     if($i%4==0)
         echo "</tr><tr>";               
echo "</table>";  
于 2012-09-21T04:35:20.607 に答える
0

ユーザー配列関数:array_chunk();

$input_array = array('a', 'b', 'c', 'd', 'e');
$t = array_chunk($input_array, 4);

It will give output like this : 

Array
(
[0] => Array
    (
        [0] => a
        [1] => b
        [2] => c
        [3] => d        

    )

[1] => Array
    (
        [0] => e
    )

)

for / foreachループを使用できます:

<table>

for($i ; $< count($t); $i++)
{
    <tr>

         for($j = 0 ; $j < 4 ; $j++) 
         {
             <td>echo $t[$i][$j];</td>
         }

    </tr>
}
</table>
于 2012-09-21T04:34:33.173 に答える