0

MySql配列からフェッチされるプロファイル画像の数を6つのプロファイル画像に制限する方法を知っている人はいますか?

ありがとう

コード:

   $newest_set = get_newest_profile() ;

    while ($newest = mysql_fetch_array($newest_set )){
        echo" 
        <div class=\"mod_newest_image\">
        <a href=\"profile.php?id={$newest['id']}\"><img width=95px src=\"data/photos/{$newest['id']}/_default.jpg\" /></a>
        <div>
        <strong> {$newest['display_name']}</strong>
        <br />
        </div>
        </div>";


    }
?>
4

3 に答える 3

2

SQLにLIMIT句を追加します

ORDER BY `date_column` DESC LIMIT 6
于 2012-10-08T11:31:32.167 に答える
0

クエリに制限を使用できます

 SELECT * FROM `your_table` LIMIT 0, 6 // takes the rows from the results 0 - 6

または、カウンターを使用することができます

$fetch_counter = 0;
while ($newest = mysql_fetch_array($newest_set ) && $fetch_counter < 6){
        echo" 
        <div class=\"mod_newest_image\">
        <a href=\"profile.php?id={$newest['id']}\"><img width=95px src=\"data/photos/{$newest['id']}/_default.jpg\" /></a>
        <div>
        <strong> {$newest['display_name']}</strong>
        <br />
        </div>
        </div>";
        $fetch_counter++;
    }

fetch_counter は 0 から始まることに注意してください。したがって、それが 6 の場合、フェッチは既に 7 回実行されています。

于 2012-10-08T11:32:00.043 に答える
0

SQL クエリに制限を設定します。お気に入り、

$sql=mysql_query("select fields from tablename where conditions limit 0,6");
于 2012-10-08T11:33:09.077 に答える