0

i have that code, and i want to limit the result to 10 max. how can i do that?

    <?php 
    $actors = rtrim($movie_info[0]->actors, ", "); 

    if(stristr($actors, ",")) {
        $actors = explode(",", $actors);
        array_walk($actors, 'add_url_on_tags', '/actor');
        echo ul($actors, array("class" => "genres2"));
        echo '<div style="clear:both;"></div>';
    }elseif(!empty($actors)) {
            echo '<a href="/actor/'.url_title($actors).'">'.$actors.'</a><br />'; 
    }else{
        echo 'empty';
    }

    ?>

thank for your help!

4

2 に答える 2

2

あなたが探しているのは $actors = array_slice($actors, 0, 10); です。

<?php 
$actors = rtrim($movie_info[0]->actors, ", "); 

if(stristr($actors, ",")) {
    $actors = explode(",", $actors);
    $actors = array_slice($actors, 0, 10);
    array_walk($actors, 'add_url_on_tags', '/actor');
    echo ul($actors, array("class" => "genres2"));
    echo '<div style="clear:both;"></div>';
} elseif(!empty($actors)) {
        echo '<a href="/actor/'.url_title($actors).'">'.$actors.'</a><br />'; 
} else{
    echo 'empty';
}

?>
于 2013-09-23T23:32:39.557 に答える
0

上記のコードを使用して結果を選択するだけでなく、おそらく SQL で実行する必要があります。

select
    *
from
    yourTable
where
    someColumn=SomeCondition
order by
    someColumn
limit 10
^^ This is the clause to add.

最初の 10 件の結果のみが返されます

次のように値をもう 1 つ追加することで、ページネーションに使用できます。

limit 10,10

これで 10 件の結果が返されますが、最初の 10 件はスキップされます (基本的に結果 11 ~ 20 が表示されます)。

于 2013-09-23T23:33:42.173 に答える