php
  • pagination
  • 2013-07-30 111 views 0 likes 
    0

    有配有3×3 的佈局做分頁問題的3x3這是我while循環,嘗試了幾個分頁,但過於複雜分頁,在每個頁面

    while($row = mysqli_fetch_array($result)){ 
        $id = $row['id']; 
        $name = $row['name']; 
        $picture = $row['picture']; 
    
        $rowPic = "<td><a href='dologinuser.php?id=$id'>"; 
        $rowPic .= "<img width='200px' height='133px' src='images/$picture' />"; 
        $rowPic .= "</a><br/>"; 
        $rowPic .= "<strong>$name</strong>"; 
    
        echo $rowPic; 
    
        $split++; 
        if ($split%3==0){ 
        echo '</tr><tr>'; 
    
    +1

    貼全代碼 – Kalai

    +0

    我有分頁不知道,一切都太複雜:/ – ben

    +0

    http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and。 HTML – ben

    回答

    0

    如何做這樣的事情?我相信這樣更具可讀性。

    <?php 
    // Grouping the code into table-like array 
    $count = 0; 
    while($row = mysqli_fetch_array($result)) { 
        $table[$count/3][$count % 3] = $row; 
        $count++; 
    } 
    
    // Constructing HTML code 
    $html = "<table>"; 
    foreach($table as $row) { 
        $html .= "<tr>"; 
        foreach($row as $col) { 
         $id = $col['id']; 
         $html .= "<td>" . "whatever you want to put" . "</td>"; 
        } 
        $html .= "</tr>"; 
    } 
    $html .= "</table>"; 
    ?> 
    
    相關問題