我有一个按钮点击事件
private void button2_Click(object sender, EventArgs e)
{
NameValueCollection userInfo = new NameValueCollection();
userInfo.Add("cardno", textBox6.Text);
byte[] getCart = client.UploadValues("http://eallowance.x10host.com/v1/getCart.php", "POST", userInfo);
}
将调用我的getCart.php
<?php
$cardno = $_POST['cardno'];
include_once('../includes/constants.php');
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
$query = "SELECT * FROM costing WHERE cardno = $cardno;";
$result = mysqli_query($con,$query);$response = array();
while($row = mysqli_fetch_array($result)){
array_push($response,array('cardno'=>$row[1],'product_id'=>$row[2], 'name'=>$row[3], 'quantity'=>$row[4], 'price'=>$row[5], 'category'=>$row[6]));
}
mysqli_close($con);
echo json_encode(array('cart'=>$response));
并将以JSON格式回显数组:
{"cart":[{"cardno":"3333333333","product_id":"10000104","name":"Hotsilog","quantity":"1","price":"35","category":"breakfast"},{"cardno":"3333333333","product_id":"10000131","name":"Fudgee bar choco","quantity":"1","price":"7","category":"snacks"}]}
有一列product_id,名称,数量,价格和类别。
我使用免费托管网站,不允许远程访问数据库,因为它是免费的,所以我必须使用PHP,即时通讯使用我的PHP在我的Android应用程序中写的Java。我是c#的新手,不知道该怎么称呼我的问题。如何使用相同的列将JSON数组响应保存到本地数据库。