在列中获取mysql结果

时间:2012-01-19 04:11:07

标签: php

我希望将我的mysql获取列表分成2列。例如

A    |     D
B    |     E
C    |     F

我想使用table而不是< UL><立GT;

<?php
        $sql = mysql_query("SELECT * FROM poet WHERE status='Publish' ORDER BY name ") or die(mysql_error());
        $total_rows = mysql_num_rows($sql);
        while ( $result = mysql_fetch_assoc($sql) ) {   ?>
    <tr>    
        <td class="navigation"><?php echo fetch_table_poet( $result["pid"], 1, 3); ?></td>
        <td class="navigation"><?php echo fetch_table_poet( $result["pid"], 1, 3); ?></td>
    </tr>   

<?php } ?>

我有这种结构。

注意 - 我希望使用PHP执行我的解决方案,而不是使用jquery和javascript。

1 个答案:

答案 0 :(得分:1)

<?php
    $sql = mysql_query("SELECT * FROM poet WHERE status='Publish' ORDER BY name ") or die(mysql_error());
    $total_rows = mysql_num_rows($sql);

    $resultSet = array();
    while ( $row = mysql_fetch_assoc($sql) ) {
        $resultSet[] = $row;
    }

    $halfLength = count($resultSet) / 2;
    for ($i = 0; $i < $halfLength; $i++) {
?>
    <tr>    
        <td class="navigation"><?php echo fetch_table_poet( $resultSet[$i]["pid"], 1, 3); ?></td>
        <td class="navigation"><?php echo fetch_table_poet( $resultSet[$halfLength + $i]["pid"], 1, 3); ?></td>
    </tr>   

<?php } ?>