RE: collapse SELECT from multiple tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



NO Spanky!

I figured it was implied that I was looking for a PHP solution since I
posted to a PHP list!

I also didn't ask for help with HTML output.  I was asking for help with
PHP output!

Let me try to explain it a little better...

I need to produce an array of results from two tables.  The first table
contains the unique records, let's call it 'customers'.  The second
table, let's call it 'orders', contains records that are referenced to
'customers' via a 'customerID' field that correlates to the
'ID' ("primary_key") field in 'customers'.

What I'm after is a multidimensional array that contains a list of
information which includes 'ID' from customers, 'name' from customers
and 'order_info' from 'orders' which is collapsed into a field of the
new multidimensional array similar to the following:

OUTPUT equivalent to
$array[0] = array('ID' => 1, 'name' => 'joe', 'order_info' => 'part1,
part2, part3');
$array[1] = array('ID' => 2, 'name' => 'jim', 'order_info' => 'part1,
part5, part9');
$array[2] = array('ID' => 3, 'name' => 'moe', 'order_info' => 'part2,
part3, part7');

'customers'
| ID | name |
| 1  | joe  |
| 2  | jim  |
| 3  | moe  |

'orders'
| ID | customerID | part  |
| 1  | 1  	  | part1 |
| 2  | 1  	  | part2 |
| 3  | 1  	  | part3 |
| 4  | 2  	  | part1 |
| 5  | 2  	  | part5 |
| 6  | 2  	  | part9 |
| 7  | 3  	  | part2 |
| 8  | 3  	  | part3 |
| 9  | 3  	  | part7 |

Hope this clears it up a bit.


On Thu, 2005-03-24 at 13:46 -0600, Jay Blanchard wrote:
> [snip]
> Your example doesn't produce the desired the results!
> 
> The reason I posted to the PHP list was I thought I would have to apply
> some ARRAY functions to produce the output I'm looking for.  Your
> example did nothing more than mine produced.
> [/snip]
> 
> 
> It produces EXACTLY what you asked for in the OP. You didn't ask "how do
> I make this look pretty with PHP?"
> 
> In order to do that, do this...
> 
> echo "<tr>";
> echo "<td>".$id."</td>";
> while($id){
> 	echo "<td>".$data."</td>"
> }
> echo "</tr>";
> 
> Is that better Sparky?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux