php - Get Mysql data and split be delimiter -
i makeing store. when user purchase item in mysql database added purchased product id 1 or 2 or both. suppose user purchases both (id 1 , 2) want mysql column purchases
of table users
show 1,2
, can that. main part comes how can result in php , separate string delimiter ,
in loop numbers separately , perform this:
//inside loop $i incrementing till no more delimiter found. if($purchase[$i] == 1){ echo 'you purchased '.$i.''; }
basically want store purchased in purchases
column in users
separated comma retrieve result, separate comma compare each number in php.
ps. noob here!
this bad database design, should create table separate row each purchase. if you're stuck this, utilize explode()
:
$purchases = explode(',', $row['purchases']); foreach ($purchases $purchase) { echo 'you purchased '.$purchase.'<br>'; }
php html mysql sql delimiter
No comments:
Post a Comment