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>
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
more details you can check this also How to use GROUP BY to concatenate strings in MySQL?