How can I insert an array into a database in one row
prod_id | user_id | quantity
1111 | 5 | 123
1234 | 5 | 11
234 | 5 | 1
if I have this table and want to select prod_id for each user and insert it into another table as
prodid qun userid
1111,1234,234 123,11,1 5
How I can get this result?
I try to use json but it returned an array and didn't store in the database.
<?php
$sql = "select * from cart where userid=5";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$prodid = $row['proid'];
$qun = array($row['qun']);
$prod[] = array('prodid' => $prodid);
$quantity[]=array('$qun' => $data);
}
$quntatity= json_decode(json_encode($qun ));
$products= json_decode(json_encode($prod));
$sql = "insert into products( userid,products ,quantity) values('5',$products','$quntatity')";
mysql_query($sql) or die(mysql_error()) ;
?>