php - JSON Encoded data not accessible -


I have inquired data from the database using a model.

  echo $ user = user:: where row ('username' and 'password =?', Array ($ user name, $ password)) - & gt; get ();  

The output is in JSON format

  [{"id": 1, "name": "abhijit", "username": "now" , "Made_t": "2014-07-31 20:07:35", "updated_at": "2014-07-31 20:07:35"}]  

But when I Try to echo out a field, I get no indication error.

  resonance $ user-> Id; // gives an error in getting the pointer to say  

You will not see and agree to the structure habit of. In addition, you need the json_decode string. Then use print_r to see the structure:

  $ result = json_decode ($ user); $ Return result [0] - & gt; Id;  

or (PHP> = 5.4.0 I think):

  echo json_decode ($ user) [0] - & gt; Id;  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -