试试下面的代码:
MySQL select 10 random rows from 600K rows fastORDER BY RAND()
或者生成10个随机数,然后用随机数查询。
下面是字符串$query="select * from member where fenlei in (1,2,3,4) order by id desc"
$result=mysql_query($query,$db)
$len=1
$i = 0
while ($res=mysql_fetch_array($result))
{
$arraylist[$len].=$res['fenlei'].'-'.$res[name].'<br>'
$i++
if(is_int($i/10))
{
$len++
$i = 0
}
}
echo $arraylist[1]
echo $arraylist[2]
echo $arraylist[3]
echo $arraylist[4]
下面是数组,
$query="select * from member where fenlei in (1,2,3,4) order by id desc"
$result=mysql_query($query,$db)
$len=1
$i = 0
while ($res=mysql_fetch_array($result))
{
$arraylist[$i] = $res[name]
$i++
$tr_list[$len] = $arraylist
if(is_int($i/10))
{
$len++
$i = 0
}
}
print_r($tr_list[1])
print_r($tr_list[2])
print_r($tr_list[3])
print_r($tr_list[4])
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)