-1

I have database table like this

Treatment_ID       Drugname
 1                 panadol
 1                 piriton
 1                 Parasitamo

I want to display this information in a html table as follows

 treatmentid          drugname
    1                panadol,piriton,Parasitamo    

How I can display as above html table?

Dan
  • 9,391
  • 5
  • 41
  • 73
user3933325
  • 19
  • 1
  • 3
  • 1
    [`GROUP_CONCAT`](http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat), be very aware of `group_concat_max_len`. – Wrikken Aug 19 '14 at 16:19
  • You can get your results from the DB then just concat them in the scripting language of your preference. Every lang has something of this sort. PHP has `implode(', ', $result)` javascript has `results.join(',')` and so on. I don't think there's a way to get the result you want straight from the database. – Eduardo Romero Aug 19 '14 at 16:28
  • Welcome to stackoverflow. you can have a look here http://stackoverflow.com/tour, just to know how to accept answer and so on. @user3933325 – Md. Salahuddin Aug 19 '14 at 17:13

1 Answers1

0

You can do it using group_concat like this

SELECT Treatment_ID as treatmentid, group_concat(Drugname SEPARATOR ',' ) AS drugname
FROM tablename GROUP BY Treatment_ID
Md. Salahuddin
  • 1,062
  • 15
  • 22