简体   繁体   中英

PHP PDO FETCH_ASSOC check value in next row before next while loop

Simple question, difficult to solve. I use a while loop to display the results of mu PDO query, like this

while($data = $stmt->fetch( PDO::FETCH_ASSOC )){ 
   //if the next row has an other value   
   //pass row to Class (to compose HTML object)
   //if the same do something else

}

Is there a way to see what the value is in the next row before ending the while loop? If the value is the same in the next row i want to do something...

it should be something like this:

$i = 0;
while($data = $stmt->fetch( PDO::FETCH_ASSOC )){ 
//Display row
echo '$data['test']['$i']';
if($data['test'][$i] == $data['test'][$i + 1]){
    //do something...
}
$i++;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM