Heim  >  Artikel  >  Backend-Entwicklung  >  请问高人看看这段代码那里错了,运行结果死循环

请问高人看看这段代码那里错了,运行结果死循环

WBOY
WBOYOriginal
2016-06-13 12:18:31847Durchsuche

请教高人看看这段代码那里错了,运行结果死循环。
$result=mysql_query("SELECT * FROM st where cid = 1");
$max_num=mysql_num_rows($result);//取得数据库的记录数 
srand((double)microtime()*10000000); //生成随机数种子。 


$se_pos=rand(0, $max_num-1); //从0到最大记录数取随机数 
$length=1; //设定共取多少条记录 
//下面是取出指定数目的记录。 
$result_lim=mysql_query("select * from st  where cid = 1 limit $se_pos,$length"); 
$myrow_lim=mysql_fetch_array($result_lim); 


$se_pos1=rand(0, $max_num-1);
$result_lim1=mysql_query("select * from st  where cid = 1 limit $se_pos1,$length"); 
$myrow_lim1=mysql_fetch_array($result_lim1);


while($myrow_lim=$myrow_lim1) {
$se_pos1=rand(0, $max_num-1);
$result_lim1=mysql_query("select * from st  where cid = 1 limit $se_pos1,$length"); 
$myrow_lim1=mysql_fetch_array($result_lim1);



------解决思路----------------------
$result_lim1=mysql_query("select * from st  where cid = 1 limit $se_pos1,$length");  //除非出错,总是返回至少包含一条记录的结果集
$myrow_lim1=mysql_fetch_array($result_lim1);//所以 $myrow_lim1 总是为非空的数组

既然 $myrow_lim1 非空,那么这个循环怎么会终止呢?
while($myrow_lim=$myrow_lim1) {

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn