Closed Thread Icon

Topic awaiting preservation: Check field value against next row Pages that link to <a href="https://ozoneasylum.com/backlink?for=26513" title="Pages that link to Topic awaiting preservation: Check field value against next row" rel="nofollow" >Topic awaiting preservation: Check field value against next row\

 
Author Thread
Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted 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++;
}



It's not working like it's supposed to, though. Any ideas?

(Edited by Kristo on 08-23-2005 02:40)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-23-2005 02:42

I'm not familiar with this language (php?), but should that = in the if be a == ?


 

Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted 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.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted 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

Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted 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!

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-23-2005 07:10

depending on what you're doing, the 'group by' sql clause may be of use to you...

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted 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

« BackwardsOnwards »

Show Forum Drop Down Menu