【发布时间】:2015-07-26 14:06:06
【问题描述】:
正如标题所说。我应该在我的 java 代码中包含哪些代码,以便我可以检索并将其传递给我的 PHP。
这是我的 PHP 代码
<?PHP
include_once("connection.php");
if(isset($_POST['TableNum'])){ $TableNum = $_POST['TableNum']; }
$TableNum = null;
$sql = "SELECT Name, Price, orderlist.Quantity FROM menu INNER JOIN orderlist ON orderlist.MenuID=menu.MenuID WHERE orderlist.TableNum='+$TableNum+' ";
$result = mysqli_query($con,$sql);
$json = array();
if(mysqli_num_rows($result)){
while($row=mysqli_fetch_assoc($result)){
$json['menu'][]=$row;
}
}
mysqli_close($con);
echo json_encode($json);
这是我的 Java 代码
我需要将此变量作为我的 where 子句传递到我的 php 脚本中。
final TextView idtable = (TextView)findViewById(R.id.lblTableNum);
final TextView idtable = (TextView)findViewById(R.id.lblTableNum);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Orderlist.this);
String aa = getResources().getString(R.string.Table_Num);
String tableID = sp.getString(getString(R.string.Table_Num), aa);
idtable.setText(tableID);
ListView lv = (ListView) findViewById(R.id.listView1);
String url = "http://192.168.123.1/1purple/readOrder.php";
try {
JSONParser jParser = new JSONParser();
JSONObject table = jParser.getJSONFromUrl(url);
JSONArray data = table.getJSONArray("menu");
//JSONArray data = new JSONArray(getJSONUrl(url));
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("Name", c.getString("Name"));
map.put("Quantity", c.getString("Quantity"));
map.put("Price", c.getString("Price"));
MyArrList.add(map);
}
SimpleAdapter sAdap;
sAdap = new SimpleAdapter(Orderlist.this, MyArrList, R.layout.orderlist_arrangement,
new String[] {"Name", "Quantity", "Price"}, new int[] {R.id.textView1, R.id.textView2, R.id.textView3});
lv.setAdapter(sAdap);
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.e("Log", "Failed" +e);
e.printStackTrace();
}
}
【问题讨论】:
-
你想做什么?您想在调用 readOrder.php 文件时将参数从应用程序传递到服务器?
-
@galath 是的,我希望它是动态的,因此我想将所述变量传递给 php 文件