Php 当页面刷新时,我如何随机化标记云区域中的链接?

Php 当页面刷新时,我如何随机化标记云区域中的链接?,php,tag-cloud,Php,Tag Cloud,代码运行正常,但我仍然希望在页面刷新时生成随机结果。现在代码给了我一些结果,比如链接n.1,2,3,4,5。。。我不希望它们是随机的,比如3,9,1 代码如下: <?php function print_cloud() { global $use_ads_scrl; $res=""; if ($use_ads_scrl=="yes"){$res=print_cloud2();} return $res; } function print_cloud2() { global $ta

代码运行正常,但我仍然希望在页面刷新时生成随机结果。现在代码给了我一些结果,比如链接n.1,2,3,4,5。。。我不希望它们是随机的,比如3,9,1

代码如下:

<?php


function print_cloud()
{ global $use_ads_scrl; $res=""; if ($use_ads_scrl=="yes"){$res=print_cloud2();}  return $res; }

function print_cloud2()
{

global $table_ads, $HTTP_GET_VARS;

$city_sch="";
if ($HTTP_GET_VARS['city']!=""){$city_sch="and city='".$HTTP_GET_VARS['city']."' ";}

$sql_query="select * from $table_ads where (adcommkey is null or adcommkey=0) and visible=1 $city_sch
order by idnum desc limit 10";

$sql_res=mysql_query("$sql_query");

$min = '8'; // Minimum font size in pixel.
$max = '22'; // Maximum font size in pixel.
$decor = 'text-decoration:none;font-weight:100;'; // Inline CSS per link.

$k1=""; $html_res="";
while ($row = mysql_fetch_array($sql_res)){
$k1="1";
if($row['adphotos']=='yes'){$check_ph=$photo_mark;} else {$check_ph="";}

$html_res=$html_res."
<a style=' ".$decor." font-size:".rand($min,$max)."px; font-family:tahoma,sans-serif; color:#3B5998;'    href='index.php?md=details&id= ".$row['idnum']." '> ".$row['title']." </a> 
";


}

$html_res="
$html_res
";

if ($k1==""){$html_res="";}

return $html_res;
}

?>

更改

order by idnum desc limit 10

它将从您的表中返回10个随机结果

编辑:若要从最近的X个条目返回随机结果,您可以尝试使用子查询返回最近的10个结果,然后对该查询的结果进行随机排序

SELECT *
FROM (SELECT * FROM $table_ads
      WHERE (adcommkey is null or adcommkey=0)
      AND visible=1
      ORDER BY idnum DESC LIMIT 10) `recent`
ORDER BY RAND()

Jap,已经这样做了,但是你没有得到最后10个添加的链接,而是从所有数据库中随机抽取:(我想从最后10个添加的链接中随机抽取,所以你可以从当天的新闻中随机抽取。谢谢你,像个魔咒一样地咀嚼:)
SELECT *
FROM (SELECT * FROM $table_ads
      WHERE (adcommkey is null or adcommkey=0)
      AND visible=1
      ORDER BY idnum DESC LIMIT 10) `recent`
ORDER BY RAND()