You are here: Re: display multiple « All PHP « IT news, forums, messages
Re: display multiple

Posted by Rik on 03/01/07 23:30

Pankaj <panahuja@gmail.com> wrote:
> My sql query is giving me multiple records - producers, masters and
> models. I want to display all models belonging to a particular
> producer in a table column seperated by comma. However, I am unable to=

> do so. All my records get displayed in a seperate row. How can I get
> this done.
>
> eg.
>
> Table Producers
> producer_id producer_name

> Table Models
> model_id producer_id model_name

> I want results to be in the format
>
> Producer Name Model Name
> A ABC, DEF, QWE
> B ASD, ZXC

No PHP question, but just for the heck of it, something like this will =

work in MySQL (untested):

SELECT
p.`producer_name` as 'name',
GROUP_CONCAT(m.`model_name` SEPARATOR ', ') as 'models'
FROM `Producers` p
LEFT JOIN `Models` m
ON m.`producer_id` =3D p.`producer_id`
GROUP BY `producer_name`

-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация