Reputation: 3
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!
Upvotes: 0
Views: 91
Reputation: 33502
you should probably do it in your SQL instead of only cherry picking your results via the code above.
select
*
from
yourTable
where
someColumn=SomeCondition
order by
someColumn
limit 10
^^ This is the clause to add.
Will only bring back the first ten results
you can then use it for pagination, by adding one more value like this:
limit 10,10
This will now bring back ten results, but skip the first ten (basically showing results 11-20
Upvotes: 0
Reputation: 1553
What you're looking for is $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';
}
?>
Upvotes: 2