请问高人看看这段代码那里错了,运行结果死循环
程序员文章站
2022-06-05 09:37:51
...
请教高人看看这段代码那里错了,运行结果死循环。
$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) {
$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) {
相关文章
相关视频