I have a database table package_details which include fields
- package_id
- features
- description
in features field I have stored data like feature1,fea2,fea3 and so on. I have separated features by comma.
I have to display records. Now my question is how to remove comma and display records one by one like
feature1
fea2
fea3
can anyone help me?
Thanks.
$array = explode(',' $data);
will explode your string based on comma
A simple solution :
//The initial string where ... represents more elements
$string = feature1,fea2,fea3,....;
//$items is an array which contains the elements obtained after breaking $string
$items = explode(',' , $string);
foreach($items as $item)
{
echo $iteml;
echo "</br>";
}
The solutions posted are correct but the proper way to store multiple values for a record is in a foreign key table. For example you would also create a table called features which would contain all the possible features any of your products could have. Ideally each record would have an Id as the primary key. You then would have a table called product-features. Each record would have the product id from your product table and the feature id from the features table. Hence linking the two together. For multiple features you would have multiple records with the same product id.
You would then use a join query to output the product features when displaying your product.