![]() Topic awaiting preservation: Check field value against next row (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: |
![]() I'm trying to loop through a record set and need to be able to check the value in a certain field in one row to see if it matches the value of the same field in the next row. Here's the portion of the code that I'm having the problem with: code: $num=mysql_numrows($result); $i=0; while ($i < $num) { $dateadded = mysql_result($result,$i,"dateadded"); $nextrow = mysql_result($result,$i+1,"dateadded"); if ($dateadded=$nextrow) { echo "This row was added on the SAME day as the next row"; } else { echo "This row was added on a DIFFERENT day than the next row"; } $i++; }
|
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() |
Nervous Wreck (II) Inmate From: |
![]() Man, do I feel stupid. I think I've been pouring over this code, trying different things for the past few hours. Thanks for keep it simple! Seems to be working fine now. Thx again. |
Bipolar (III) Inmate From: Australia |
![]() What is your SQL statement? You can probably do it all in 1 query and reduce your php code :P |
Nervous Wreck (II) Inmate From: |
![]() Actually, I just made up that code because it represented what I was trying to do. The actual code is much more complicated, but I've plugged this principle in and it seems to be working now. Thanks for your help! |
Maniac (V) Inmate From: under the bed |
![]() depending on what you're doing, the 'group by' sql clause may be of use to you... |
Bipolar (III) Inmate From: Australia |
![]() And maybe some subquery if your versions support it... mine dont |