我有一个安卓购物清单应用程序,我使用PHP设计它,我有mySQL数据库。在该数据库中,我有一个名为Products的表。在products中只有两列,list和product。每个列表将包含多个产品。我希望能够填充与所有的产品在任何列表的应用程序的用户所选择的页面。
我使用PHP与JSON从mySQL读取信息。这里类似于我想要的,但这将从数据库中读取所有列表和产品。我只想要用户在屏幕上选择的列表。
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM products") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["list"] = $row["list"];
$product["name"] = $row["name"];
// push single product into final response array
array_push($response["products"], $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);
}
?>
如有任何帮助,不胜感激
由于android应用程序需要发送一个HTTP请求来获取数据,因此传递一个带有用户在应用程序中选择的表值的get变量。然后用$_GET["table"]
在PHP中读取该值。