php - Problem in use of json_encode? -


I insert the data into the database with json_encode () , now I should get (< Code> select * to & lt; table & gt; ... ) only the name_unitsin database? I want the output to- & gt; Hats & amp; Mokhle & amp; [{"Name_units": "salam", "price_units" in fadat

database line units :

  : "", "Box_inits": "[" minibar "," mobileman "]}, {" name_units ":" mock "," value_accept ":" 4,851,269 "," checkbox_news ": [" mobleman "," tv "] } "" "" "" "," Value_anounts ":" 85,642 "," checkbox_notes ": [" minibar "," mobelman "," tv "]}]   

  $ query_hotel_search = $ this- & gt; db- & gt; query ("Select * FROM from the hotel name where the name '% $ hotel_search%' is entered ) "; $ Data = array (); foreign currency ($ Query_hotel_search- & gt; result () as the $ line) {$ units = json_decode ($ line-> units); $ data [] = array ('name' = & gt; $ line-> gt; ; Name, 'units' = & gt; $ units ['name_units']); // line 24} echo json_encode ($ data);   

This is the output above the code: < / P>

encountered a PHP error
Seriousness: Information / Message: Undefined Index: name_units
Line Number: 24

[{" Name ":" Jack "," Units ": Zero}]

you stdClass objects as a result from json_decode , instead of expecting an associative array as you think it looks like you have the JSON strings located in the same cell in your DB An array is found.

Assuming that your DB is the table structure, if you want to output

Hats & amp; Mokhle & amp; Try again:

  foreach ($ query_hotel_search-> result () as $ line) {$ units = Json_decode ($ line-> units); $ Name = ''; Foreign Currency ($ units $ unit) {$ names. = "{$ Unit-> Name_units} & amp;"; }} Echo substrust ($ name, 0, -2);    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -