This is my code, it retreives data from xampp external database and store it to an array that is parsed to json
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/conectaDB.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("select cd.id, cd.dt_ini_camp, cd.dt_fim_camp, cd.descricao, + (select sum(quantidade) from lin_doc where id_cab_doc = cd.id) as qtd from cab_doc cd where cd.id_tipo_doc = 1") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["id"] = $row["id"];
$product["dt_ini_camp"] = $row["dt_ini_camp"];
$product["dt_fim_camp"] = $row["dt_fim_camp"];
$product["descricao"] = $row["descricao"];
$product["qtd"] = $row["qtd"];
// push single product into final response array
$response["cab_doc"] = array();
array_push($response["cab_doc"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
Output:
{"cab_doc":[{"id":"69","dt_ini_camp":"2012-12-22","dt_fim_camp":"2012-12- 26","descricao":"cadqadadad","qtd":null}],"success":1}
My problem is that this is the last record and i want all, whats missing please help
$response["cab_doc"] = array();in your loop?while()loop and tell us the results.