1

我有六列输出。内容是从数组中获取的(创建为 php 数组,然后作为 js 数组发送)。包含数组 $set 的示例行如下:

 $set[] = array('q'=>'墨水','qurl'=>'001','a1'=>'o','a2'=>'ui','f'=>'m','m'=>'4sh','e'=>'3');

假设我有四行内容。我的代码目前生成这个:

Col 1 Col 2 Col 3 Col 4 Col 5 Col 6
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6

我需要将这四行放入两组主要的列中。所以像这样:

Col 1 Col 2 Col 3 Col 4 Col 5 Col 6        Col 7 Col 8 Col 9 Col 10 Col 11 Col 12
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6        Col 7 Col 8 Col 9 Col 10 Col 11 Col 12

这样做的有效方法是什么?我当前的代码如下所示:

…
$js_array = json_encode($set);
…


<table>
    <?php $counter = 0;
    while ($counter < 20) :
    $item = $set[$counter]?>
        <tr class="q<?php echo $counter; ?>">                   
            <form>
            <td><h5><?php echo $counter+1; ?></h5></td>
            <td><a class="question" href="javascript:soundManager.play('<?php echo $item['qurl'] ?>','audio/part2/type3/type3_<?php echo $item['qurl'] ?>.mp3');"><?php echo $item['q'] ?></a></td>
            <td><?php echo $item['f'] ?></td>
            <td><input class="a1" type="text" name="a1" maxlength="4" size="2" /></td>
            <td><?php echo $item['m'] ?>&nbsp;<input class="a2" type="text" name="a2" maxlength="4" size="2" /><?php echo $item['e'] ?></td>
            <td><input class="submit submit-<?php echo $counter; ?>" type="submit" value="Submit" /></td></form>
        </tr>
    <?php $counter++; ?>
    <?php endwhile; ?>
</table>
4

1 回答 1

0

你可以这样做:

$total = 24;

//loop through rows     
for($i = 0; $i < $total; $i++) {
    //start new table?
    if($i == 0 || $i == ($total/2)) {
        if($i > 0) { //second table cell values
            echo '</table>';
            $j_val = 7;
            $j = $j_val;
        } else { //first table cell values
            $j_val = 1;
            $j = $j_val;
        }

        echo '<table>';
    }

    echo '<tr>';

    $total_cells = ($j + 6);

    for(; $j < $total_cells; $j++) {
        echo '<td>' . $j . '</td>';
    }

    //reset j to default
    $j = $j_val;

    echo '</tr>';
}

echo '</table>';
于 2012-07-19T22:02:21.303 回答