0

在我的页面上,我想对数据库进行查询并对结果进行分页,以便它们根据当前查看页面的人数按降序排列。我希望它从左到右读取前三名,然后换到新行,然后从左到右再次读取结果四到六,依此类推。

所以我的表格是这样布置的:

    <div class="popular1">
                            <table class="pop-table-thumb">
                                <tr  colspan="3">
                                <div class="pop-table-header">
                            Most popular
                                </div>
                            <br>
                            </tr>
                                <tr>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="pop-thumb">
                                            <img class="img-thumb" src="Images/DefaultThumbnail.gif"/>
                                        </div>
                                    </td>
                                </tr>

                            </table>

                        </div>

我知道如何进行基本的分页并列出来自 assoc 查询的结果,例如:

    $query = mysql_query("SELECT `something` FROM `something`");
    while ($assoc_array = mysql_fetch_assoc($query)) {
        echo '<p>', $assoc_array['something'] ,'</p>';
    }

那么有人对我应该如何处理有任何想法吗?

4

1 回答 1

0

您可以使用计数器和模数轻松创建 3 个宽行%

<div class="popular1">
    <table class="pop-table-thumb">
        <tr>
            <td colspan="3"><div class="pop-table-header">Most popular</div><br></td>
        </tr>
<?php
$counter = 1; // basic counter to be used in the while loop
while($row = .....){
if($counter%3 == 1){ // if modulus == 1 (ie. 1,4,7) start a row
    echo'<tr>';}

    // This is where you can change your data from your database
    echo '<td><div class="pop-thumb"><img class="img-thumb" src="Images/DefaultThumbnail.gif"/></div></td>';

if($row%3 == 0){   // if modulus == 0 (ie. 3,6,9) close the row
    echo'</tr>';}
    $counter++;} // increase the counter
?>
    </table>
</div>
于 2013-05-06T18:43:54.633 回答