RE: collapse SELECT from multiple tables

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

 



David Christensen <mailto:davidc@xxxxxxxxxxxxxxxx>
    on Thursday, March 24, 2005 12:07 PM said:

> 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!

Yikes.

> 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'.

Yes, this is called a one-to-many relationship.

> 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');

Did you read the manual? The PHP functions for MySQL already do this
automatically! In fact they organize the output even better!

Start here: http://us4.php.net/mysql. (HINT: mysql_fetch_array().)

Next time don't be hostile and post a more clearly worded question[1].
You'll save everyone a lot of time.



Chris.

[1] Read here: www.catb.org/~esr/faqs/smart-questions.html

-- 
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