简单地说,我希望能够获取在MySQL获取数组中返回的TOP 3数组;
$getTopStats = mysql_query("SELECT * FROM users WHERE rank <= '2' ORDER BY activity_points DESC LIMIT 20");
while($topSpats = mysql_fetch_array($getTopStats)){
// $sizeotar will return either s (small) or l (large) - (large for the first top 3 users, and then small for the rest of the users)
echo '<img src="imaging/image?figure=' . $topSpats['look'] . '&size=' . $sizeotar . '&direction=2&head_direction=2&gesture=sml" align="left"></td> <td width="195px"><a href="#"><b>'.$topSpats['username'].'</b></a><br />'.$topSpats['activity_points'].' duckets';
}
我不熟悉mysql fetch数组,所以我不太擅长这样做。
答案 0 :(得分:2)
如果是,那么为什么您将LIMIT 20
添加到查询
SELECT *
FROM users
WHERE rank <= '2'
ORDER BY activity_points DESC LIMIT 3
如果你想用你的查询来做。只需使用
array_slice返回一个数组的片段
array_slice($array, 0, 3)
答案 1 :(得分:0)
如果我理解你的问题,然后给出了意见,这可能有效:
添加一个计数器,以便您决定使用哪个字符串:
for ($counter = 0; $topSpats = mysql_fetch_array($getTopStats); $counter++)
{
$sizetoar = $counter < 3 ? 'l' : 's';
...
在前三个循环中,计数器将为:0,1和2.