1

If I had a database table containing an item and whatever was wrong with that item, for example:

Car    Scratch
Car    Dent
Car    Rust
Bike   Broken light
Bike   Rust

How would I display this in an HTML table in the following format:

Car    Scratch, Dent, Rust
Bike   Broken light, Rust

To be insert into an HTML table as:

<tr>$name(Car)</tr>
<tr>$defects(scratch, dent, rust)</tr>
Michael
  • 41,989
  • 11
  • 82
  • 128
Iggy's Pop
  • 589
  • 1
  • 6
  • 24

1 Answers1

1

you can update your mysql query which select your item_name using your category as like your requirement

SELECT category, GROUP_CONCAT(CAST(item as CHAR)) as item_name FROM `table_name` group by category;

this is your final query

SELECT tank_no, GROUP_CONCAT(ng_id) as item_name FROM non_green GROUP BY `tank_no`;

where category is car,bike etc and item is scratch, dent, rust

so when you select this then you can print category and item_name and no need to process in php section.Check this attach file

checkthis

more details you can check this also How to use GROUP BY to concatenate strings in MySQL?

Community
  • 1
  • 1
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43