Get your products from the database, then use PHP's explode()
:
$products = explode(',', $productsFromDatabase);
See: http://php.net/explode
This will give you an array again. With the array, depending on what you've stored, you can just use these values to look up individual products.
foreach ($products as $values) {
// SELECT SQL statement here using a WHERE clause depending on what value you stored.
// Ex: SELECT * FROM `products` WHERE id='$value'
// Ex: SELECT * FROM `products` WHERE name='$value'
}
Assuming you're getting product names from IDs, you can utilize the foreach loop to populate an array that you can then implode for a list of product names:
$names = array();
foreach ($products as $values) {
// SELECT SQL statement here using a WHERE clause depending on what value you stored.
// Ex: SELECT * FROM `products` WHERE id='$value'
// Ex: SELECT * FROM `products` WHERE name='$value'
// Assume you have attained a $row using a select statement
$names[] = $row['name'];
}
$names = implode(',', $names);
echo $names;
This can be simplified greatly if you simply store product names instead of IDs, however I recognize that the IDs may have practical uses in other parts of your code.