Naintara Jain wrote: >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? > When you come out of your loop, either there will be one row left to print, or there were no matching rows. Suggestion one is to test for this and if there were matching rows, do a special case for the last row.
Alternatively, you are printing a row when the ID changes, that is, the last row of the 1 to 3 matching rows. Why not print the first one, not last one? You change the logic to print the first row then ignore others with the same ID. It could be that (because of an Order By clause) the last row is the correct one and the data may differ between rows with the same ID. You say you do not want to do it in the SQL statement itself, but this really is the right place. If MySQL use a LIMIT clause to only get one row, if you cannot refine the SQL statement to only retrieve one row. HTH Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php