Topic awaiting preservation: Check field value against next row (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: |
posted 08-23-2005 02:34
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 |
posted 08-23-2005 02:42 |
Nervous Wreck (II) Inmate From: |
posted 08-23-2005 02:58
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 |
posted 08-23-2005 02:59
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: |
posted 08-23-2005 03:34
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 |
posted 08-23-2005 07:10
depending on what you're doing, the 'group by' sql clause may be of use to you... |
Bipolar (III) Inmate From: Australia |
posted 08-23-2005 10:27
And maybe some subquery if your versions support it... mine dont .... An app im working on with a postgre database does though, makes for much less code |