samedi 31 janvier 2015

serializing session array and save it to database


Vote count:

0




This is my code for saving purchase order form to database..



function save(&$purchase_data,$purchase_id)
{
$success=false;

//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();

if($purchase_data)
{
if (!$purchase_id or !$this->exists($purchase_id))
{
//$purchase_data['purchase_id'] = $purchase_id = $purchase_data['purchase_id'];
$success = $this->db->insert('purchase_order',$purchase_data);
$post_array['cart']=$this->session->userdata('data');
/*print_r($post_array);
exit;*/
$purchase_id=$this->db->insert_id();
$i=0;
foreach($post_array['cart'] as $item)
{
//echo "<pre>"; print_r($item); echo "</pre>";
$query = $this->db->query("SELECT name FROM phppos_items WHERE item_id='".$item['product_id']."'");
foreach ($query->result() as $row)
{
$product_name=$row->name;

}
$product_id=$item['product_id'];
$quantity=$item['quantity'];
$unit=$item['unit'];
$unit_rate=$item['unit_rate'];
$query = $this->db->query("insert into phppos_productdetails(product_id,product_name,quantity,unit,unit_rate,purchase_id) values ('$product_id','$product_name','$quantity','$unit','$unit_rate','$purchase_id')");

$i++;
}
}
}


Now this code insert multiple rows in productdetails table but I want to serialize this array and want to store whole array in one column. So how do I do it??



asked 59 secs ago







serializing session array and save it to database

Aucun commentaire:

Enregistrer un commentaire