显示具有相同ID的数据

i have table like this,

table name:product

cart id  product_name
1        fan   
2        tv
2        laptop
3        mobile
3        charger  
3        earphone

i need to display

cart id=1
product name
fan

cart_id=2
product name
tv
laptop

cart_id=3
product name
mobile
charger
earphone

how to get this result??

there is no need for sql joins, i'm fetching all data from object using for each loop, but i'm confused how to put condition to get this result?

here cart id will be dynamic mean it will be incremented as per user create cart in their account with different products.

You need 2 tables

1. table_produk (save you product)
cart_id  product_name
1        fan 
2        tv
3        laptop
4        mobile
5        charger
6        earphone

2. table_display (store the data you want to display)
id  product_show
1        1
2        2
3        2
4        3
5        3
6        3

Codes:

SELECT table_produk.produk_name
FROM table_display
LEFT JOIN table_produk ON table_produk.cart_id = table_display.id
WHERE table_produk.cart_id = 2

Result: // tv, laptop