For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2006 > Looping query output









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Looping query output
Magnus Thyvold

2006-03-21, 9:58 pm

I have a SELECT query that joins a few tables. The resulting query result
has data that is repeated in several columns where a one to many join has
occured. I want to be able to loop the output so that info that is the same
from row to row is not repeated.

Example of returned rows:

Program Name | Timeslot | Host
Program 1 | Tuesday 8pm | Jane Doe
Program 1 | Tuesday 8pm | Jack Flash
Program 2 | Wednesday 12noon | Tom Sawyer
Program 3 | Wednesday 2pm | Huck Finn
Program 3 | Wednesday 2pm | Becky Sharp
Program 4 Thursday 11am | Anne Shirley
etc.

I don't want to repeat the full row of data whern a program has more than
one host. info about Program 1 to be output once and then loop over the
hosts like this:

Program 1
Tuesday 8pm
Jane Doe
Jack Flash

Program 2
Wednesday 12noon
Tom Sawyer

Program 3
Wednesday 2pm
Huck Finn
Becky Sharp

Program 4
Thursday 11
Anne Shirley

I've looked on the net and in my PHP books for some examples or best
pratices but have not seen anything helpful. I am still fairly new to PHP
but have worked with other languages where this was easy. I am not ready to
delved into PEAR just yet. I'd appreaciate some help or being pointed to
some resources on the net.

I have made some efforts to get this working but when looping it some rows
were being skipped in the display.
Thanks for your help.
--
Magnus Thyvold


http://www.cjsf.ca


fwdkhan@gmail.com

2006-03-24, 7:00 pm

in my opinion u can achieve this by by first taking ur query result in
an array and then matching each row with other rows if u find first 2
columns same then print column 1 and 2 once which r same and then print
the 3 column of row 1 and 2. i hope u understand what i am trying to
say.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com