[thelist] one-to-many query to PHP output

john corry john at neoncowboy.com
Mon Feb 11 19:36:00 CST 2002

I've been through the simple version of this already...but now I have a more
complicated example I need help with. I just *can't* see the required logic

I have a query that JOIN's 3 tables.

If I were to loop through the returns and output the results, I would get
something like this:

Prop Name
Prop Desc
Pic 1
Pic 2
Unit Type (for as many unique Unit Types are in the Rates table...)
Rate 1
Rate 2
Rate 3
Rate 4

But I'd get it all these repetitive times...to satisfy the multiple required
iterations through the loop...For instance, Prop Name is the same each time
through the loop, Pic 1 & 2 are different (until they've been assigned to
variables, then I don't need them anymore), Unit Type varies from property
to property, but for each Unit Type, I need to echo the 4 rates for that
Unit Type. What a mess!!

OK...so, I need the logic that will let me break it all down and only format
& echo the parts I want through each iteration of the loop.

So, I need to wind up with all those fields, but only once...god, does that
make any sense at all?

My logic is like this:

start loop
if this is the first time through the loop
	assign Prop Name and Prop Desc to variables, format and print
	if this is a new pic
		if all the pics have not been assigned
			make variables for the pics, write the tags, and print

	if this is a new unit type
		make a variable for this unit's 4 rates, format and print
		make a new <tr> for this unit type,
		make a variable for this unit's 4 rates, format and print
end loop

But...I think there are some holes in this logic...I can't see how to
pseudocode it all. If I could just see the logic/pseudocode I know I could
write the PHP to do it all...I'm just hung up on figuring it all out.

I'm about to resort to separate queries for each table...but I'll be
disappointed in myself if I hack this up like that.


John Corry

More information about the thelist mailing list