RE: collapse SELECT from multiple tables

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

 



My apologies!  I thought I was giving what I was getting as far as the
angle of my post.

I still don't think everyone is understanding what I'm after here
though.  I know how to use the mysql functions in PHP.  That is not my
problem.  I'm trying to avoid having to make multiple queries to the db
in order to combine two array results.

I understand this is a one-to-many relationship, but I'm not really
after the default output that produces.  I want the 'many' to be a
single element in the customer line array (referencing my last post.)

So if the result is that customer '1' has ordered 3 items, and each item
is a separate line in the 'orders' table that get returned from the
query, I want an array of:

$array[0] = ('ID' => 1, 'name' => 'joe', 'items' => 'part1, part2,
part3');

I don't know how to say it any plainer than that.

The original post would have produced the following:

1, 'joe', 'part1'
1, 'joe', 'part2'
1, 'joe', 'part3'

but what I'd like to get is:
1, 'joe', 'part1, part2, part3'

Thanks for your help.  I think I may have to redesign this thing to make
this easier or I maybe I just don't have the vocabulary to ask the
question correctly.

On Thu, 2005-03-24 at 12:17 -0800, Chris W. Parker wrote:
> 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