A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearComparing a value with previous row in a while loop? - page 1
User InfoPosts
Comparing a value with previous row in a while loop?#1
I(m a newbie in PHP, so forgive me for a basic question.

In a While statement, is there a way to know if a value in a row is equal to a value in the previous row?

posted date: 2009-04-11 01:52:00


Re: Comparing a value with previous row in a while loop?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-11 01:52:01


Re: Comparing a value with previous row in a while loop?#3
Just store it:$get = mysql_query("...");$previous = ((;while ($row = mysql_fetch_assoc($get)) { $current = $row[(...(]; if ($current == $previous) { // do stuff } $previous = $current;}

posted date: 2009-04-11 01:55:00


Re: Comparing a value with previous row in a while loop?#4
Thank you Cletus.

posted date: 2009-04-11 01:56:00


Re: Comparing a value with previous row in a while loop?#5
$get = mysql_query("...");$previous = ((;while ($row = mysql_fetch_assoc($get)) { $current = $row[(...(]; if ($current == $previous) { // do stuff}$previous = $current;}This example won(t work correctly. It will always skip the first record in the array.The first time through $previous will be blank so $current and $previous won(t be equal. $current will have to blank the first pass, just as previous.$current will have to be made equal inside the if loop.$get = mysql_query("...");$previous = ((;$current = ((;while ($row = mysql_fetch_assoc($get)) { if ($current == $previous) { $current = $row[(...(]; // do stuff } $previous = $current;}

posted date: 2014-12-08 13:45:00


Re: Comparing a value with previous row in a while loop?#6
good call, I also wondered why it kept skipping the first row.

posted date: 2016-03-17 12:42:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.