Re: in a logic loop!
| From: | Marek Kilimajer | Date: | Tue, 24 Sep 2002 08:14:24 +0000 |
| Subject: | Re: in a logic loop! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-117381@lists.php.net to get a copy of this message | ||
Do it after the loop finishes
while( ){
if( something ) {
print out;
reinicialize
}
}
print out
Naintara Jain wrote:
I have a logic problem: I have a complicated query. The main thing is that I have an ID, and for a particular ID, I may have between 1 to 3 rows returned. The rows returned are variable, that is for 1 particular ID there might just be 1 row and at a later time it may have 3 rows. But what I need to do is print only one row for a particular ID. Please do not suggest I do it through SQL itself, because it's after using various aggregate functions that I have arrived at the min. result set. I need the logic clarified, because it has me stumped. It will be simple for a clear-thinking individual. What I am doing is: I maintain a set of details in say $prev_row (previous row) and another in cur_row (current row). The minute my cur_row detail (one unique id) doesn't match the prev_row detail, I print out all the previous row details, and reinitialize the various variables (all in a loop). This works fine for all cases but fails for the last ID, because of the logic used. Do I need to create a special case for the last one, or can anyone suggest a better way? -Thanks Naintara