Please look at this code there is wrong, run the result of the dead loop

Source: Internet
Author: User
Ask tall man to see this piece of code there is wrong, run the result of the dead loop.
$result =mysql_query ("select * FROM St WHERE cid = 1");
$max _num=mysql_num_rows ($result);//Gets the number of records in the database
Srand (Double) microtime () *10000000); Generates a random number seed.


$se _pos=rand (0, $max _num-1); Random number from 0 to maximum record count
$length = 1; Set the number of records to be taken together
The following is the removal of the specified number of records.
$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);
}


------to solve the idea----------------------
$result _lim1=mysql_query ("select * FROM St WHERE cid = 1 limit $se _pos1, $length"); Always return a result set containing at least one record, unless an error occurs
$myrow _lim1=mysql_fetch_array ($result _lim1);//So $myrow _lim1 is always a non-empty array

Since $myrow _lim1 is not empty, how can this cycle end?
while ($myrow _lim= $myrow _lim1) {
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.