php - Database Row with Multiple JSON values - How to get a specific value -


so question of day be, how can specific value single database row has multiple json values using php.

the data has been put in database such:

a:7:{s:5:"cname";s:4:"enes";s:6:"cemail";s:22:"enesdemirict@gmail.com";s:8:"caddress";s:18:"florisvosstraat 56";s:4:"ctel";s:12:"+31685035990";s:9:"ccomments";s:5:"fdfsf";s:15:"wppizza-gateway";s:3:"cod";s:12:"wppizza_hash";s:64:"34e24d48186596cae445d52c5b0650d20c8a7c215ef1fe323ca6f09b7f804a8d";} 

so ofcourse have code database following.

<?php   header('content-type:application/json');  mysql_connect('localhost','root','') or die(mysql_error());  mysql_select_db('depits');  $select = mysql_query("select * `test_json`");  $rows=array();   while($row=mysql_fetch_array($select)) {     $rows[] = $row; }  echo json_encode($rows);  ?> 

how able process data received , example, value of name , email. if vague or not question please comment on might better sake of clarity.

your json seems incorrect, http://jsonlint.com/

this how it:

<? $test = '{"john": {"status":"wait"},"jennifer":{"status":"active"},"james": {"status":"active", "age":56,"count":10,"progress":0.0029857,"bad":0}}';  // decode json  associative arrays $decoded = json_decode($test, true);  //easy read array echo "<pre>"; print_r($decoded); echo "</pre>";  // james age  echo "age: ". $decoded['james']['age']; ?> 

i guess looking for. names need foreach loop

<? $json = '{ "people":      [{         "name":"peter",         "age" :"50"     },{         "name":"phil",         "age" :"25"     },{         "name":"mike",         "age" :"23"     }]  }';  // decode json  associative arrays $decoded = json_decode($json, true);  // loop through array foreach($decoded['people'] $key => $value) {      echo 'name: ' . $value['name'] . ' age: ' . $value['age'] . '<br>';  } ?> 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -