query in php

Posted on 2014-08-05
Last Modified: 2014-08-05
I have the following table

name    zone   site    location
rt              2         5         street1
rt              5         8         street29
ty              3         9         street3i
vt              1          1        street4
vt               5         1        street10

i want something like that
name    zone   site    location
rt              2,5         5,8         street1,street29
ty              3         9         street3i
vt              1,5          1,1        street4,street10

i am using php and mysql, how i can do a query from table 1 to produce the table2 ? Any idea?
Question by:joyacv2
    1 Comment
    LVL 58

    Accepted Solution

    SELECT name, 
    GROUP_CONCAT(location SEPARATOR ', ') 
    FROM table 
    GROUP BY name

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now