請教高人看看這段代碼那裡錯了,運行結果死迴圈。

來源:互聯網
上載者:User
$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) {

謝謝大大的指點。。
我這裡的$myrow_lim和$myrow_lim1都是代表的字串,不是數值。。那麼請問這個迴圈該怎麼寫?

問題已經解決。。。謝謝

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.