John Davidson

Get JSON Encode Data PHP CodeIgniter

0 comments
Message:


I have json data stored in database with field name "field_form" like this:


[
{
"panjang": "200",
"tipe_data": "text",
"nama_field": "nama lengkap"
},
{
"panjang": "201",
"tipe_data": "number",
"nama_field": "tahun lahir"
}
]

I need to get "nama_field" data in PHP CodeIgniter controller, when i get the data with code:


$data_form = $this->perizinan_model->get_sub_field_form($id_jenis_izin)->result();

foreach($data_form as $data_field){
var_dump(json_decode($data_field->field_form));
}


var_dump result is


array(2) { [0]=> object(stdClass)#21 (3) { ["panjang"]=> string(3) "200" ["tipe_data"]=> string(4) "text" ["nama_field"]=> string(12) "nama lengkap" } [1]=> object(stdClass)#23 (3) { ["panjang"]=> string(3) "201" ["tipe_data"]=> string(6) "number" ["nama_field"]=> string(11) "tahun lahir" } }

But, i just want to get nama_field data, and store it on array. Thanks before.



My Answer:
$json_data = $this->db->get('table_name')->result_array();
echo json_encode($json_data);

Rate this post

5 of 5 based on 7663 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us