i trying send data mysql database using json. long 1 post in database works, when more rows nor working anymore.
here php code: // array json response $response = array();
$data = new cdatabaseinfo(); $result = $data ->selectall(); $data->closedatabase(); // check empty result if (isset($result)) { $response["products"] = array(); foreach($result $value) { $product = null; $product = array(); $product["pid"] = $value["pid"]; $product["name"] = $value["name"]; $product["price"] = $value["price"]; $product["description"] = $value["description"]; $product["created_at"] = $value["created_at"]; $product["updated_at"] = $value["updated_at"]; array_push($response["products"], $product); } // success $response["success"] = 1; echo json_encode($response, true); echo "var dump <br>"; var_dump($response); } here comes result of var_dump:
array(2) { ["products"]=> array(2) {[0]=> array(6) { ["pid"]=> string(1) "1" ["name"]=> string(6) "festis" ["price"]=> string(5) "20.00" ["description"]=> string(9) "god dryck" ["created_at"]=> string(19) "2015-07-09 20:31:30" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } [1]=> array(6) { ["pid"]=> string(1) "4" ["name"]=> string(4) "cola" ["price"]=> string(5) "12.00" ["description"]=> string(11) "en fin läsk" ["created_at"]=> string(19) "2015-07-20 20:29:03" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } } ["success"]=> int(1) } thanks!
there no such thing json_encode($response, true);
be sure right data database. beside little error, code should run correctly.
Comments
Post a Comment