php - how can insert array in database as one row with comma between each element -


how can insert array database in 1 row

    prod_id | user_id | quantity      1111    | 5       | 123     1234    | 5       | 11     234     | 5       | 1 

if have table , want select prod_id each user , insert table as

    prodid          qun        userid     1111,1234,234   123,11,1     5 

how can result?

i try use json returned array , didn't store in database.

<?php     $sql = "select * cart 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 products( userid,products ,quantity) values('5',$products','$quntatity')";     mysql_query($sql) or die(mysql_error()) ;   ?> 

using group_concat resolve this

   $sql ="select group_concat(prodid separator ', '),group_concat(quantity separator ', '),userid     cart userid=5 group userid;" 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -