dsdtszi0520538 2012-04-23 20:10 采纳率: 100%
浏览 13

三列PHP结果表

I'm trying to display my mysql query into a fairly unique table. The characteristics are as follows:

  1. The results table has 3 columns
  2. The top right cell is reserved for other content

[result1][result2][content]

[result3][result4][result5]

[result6][result7][result8]

...etc

The query can bring back as few as 1 result. But I'm struggling to get what i need included in the loop.

If anyone knows how to go after something like this, I'd love some help! Thanks in advance!

EDIT ** HERE IS MY CODE SO FAR

the results are coming through in three columns, but I can't get the condition to display other static content in the top right cell.

$row = 0;
$column = 0;
echo "<table>";
while($row = mysql_fetch_assoc($result)) {
    if ($column == 0) {echo "<tr>";}
    if (($column == 2) && ($row == 0)){echo "<td>content</td></tr><tr>";}
  echo "<td>".$row['business']."</td>";
  $column++;
  if ($column >= 3) {
    $row++;
    echo "</tr>";
    $column = 0;
  }
}
echo "</table>";
  • 写回答

2条回答 默认 最新

  • dongyi1921 2012-04-23 20:22
    关注

    Assuming a pure html table, you'd have

    $row = 0;
    $column = 0;
    echo '<table>';
    while($row = mysql_fetch_assoc($result)) {
       if ($column == 0) {
          echo '<tr>';
       }
       if (($column == 2) && ($row = 0))
          echo '<td>content</td></tr><tr>'; // output special content, start new row
       }
       echo "<td>$row[something]</td>";
       $column++;
       if ($column >= 3) {
          $row++;
          echo '</tr>';
          $column = 0;
       }
    }
    echo '</table>';
    

    probably won't work as-is, but should give you the general idea. Basically just output rows/columns until you reach the 1st row/3rd column then output your special content, otherwise just out

    评论

报告相同问题?