mysql - how to retrieve serialize data into tabel in php using unserialized -
greeting, name tri. working on serialize data database in mysql php. after serialized data database, don't know how retrieve table using unserialized. after unserialized data database, data converted array when use print_r();
method.
this code :
$cart_id = 9; $sql = "select details shop id_order =".$cart_id; $result = $this->db->query($sql); if($result->num_rows()>0){ foreach ($result->result_array() $row) { $cart = unserialize($row['details']); } echo '<pre>'; echo print_r($cart); echo '</pre>';
i stored serialized data column details inside orders table.
but when try retrieve serialized colum details using unserialized, can show of them using print_r().
this print_r()
result code after unserialized :
array ( [c4ca4238a0b923820dcc509a6f75849b] => array ( [rowid] => c4ca4238a0b923820dcc509a6f75849b [id] => 1 [qty] => 4 [name] => polo shirt [price] => 15 [subtotal] => 60 ) )
my question is, how can display table per item?
based on question , request example, should started:
if ( $result->num_rows() > 0 ) { echo '<table>'; foreach ( $result->result_array() $row ) { echo '<tr>'; $cart = unserialize( $row['details'] ); echo '<td>' . $cart['rowid'] . '</td>'; echo '<td>' . $cart['id'] . '</td>'; echo '<td>' . $cart['qty'] . '</td>'; echo '<td>' . $cart['name'] . '</td>'; echo '<td>' . $cart['price'] . '</td>'; echo '<td>' . $cart['subtotal'] . '</td>'; echo '</tr>'; } echo '</table>'; } }
Comments
Post a Comment