Reputation: 1
Does anyone know how I could limit the number of profile images that are fetched from MySql array to say 6 profile images?
Thanks
Code:
$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>";
}
?>
Upvotes: 0
Views: 2834
Reputation: 2051
Set a limit on your sql query. Like,
$sql=mysql_query("select fields from tablename where conditions limit 0,6");
Upvotes: 0
Reputation: 6653
You could use an limit to your query
SELECT * FROM `your_table` LIMIT 0, 6 // takes the rows from the results 0 - 6
Or you can use an counter
$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++;
}
Note that fetch_counter starts at 0, so if it is 6, the fetch is runned 7 times already.
Upvotes: 0