In the traversal result set, check whether the values of the two cycles are 0.

Source: Internet
Author: User
In the traversal result set, determine whether the values of the two cycles are 0. that is to say, & nbsp; Table A contains 10 data records with the field phone. after select, & nbsp; & nbsp; use while traversal to judge in while. if the phone value of $ I and the phone value of $ I + 1 are both equal to 0, then, in the traversal result set, determine whether the values of the two loops are 0.
That is to say, table A has 10 data records and the field is phone. after the select statement is used, the while statement is used to traverse and judge in the while statement, if the phone value of $ I and the phone value of $ I + 1 are both equal to 0, perform related operations. How to write this loop?

The code has been written to this:


$i=0;
while ($row = $db->fetch_array($result)){
$i++;
}
Share:
------ Solution --------------------
$ Last = array ();
While ($ row = $ db-> fetch_array ($ result )){
If ($ last & $ row ['phone'] = 0 & $ last ['phone'] = 0 ){
// Process the code
}
$ Last = $ row;
}


You can also directly query

set @last:='';
select @last as last, phone, @last:=phone from tbl_name

Direct comparison or post-reading
------ Solution --------------------
Reference:
Quote: reference:

Add a counter to determine the continuity of the counter. If yes, execute it. otherwise, reset it.

Otherwise, convert the result to an array and use foreach to perform subscript operations.

I am a newbie. thank you very much for the operation of the counter.

The idea is similar to that of #4, but I used cache data directly, which is more concise than using a counter (the counter is the cache subscript $ I), so I won't be ugly.

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.