Hello everybody I'm doing a client/server app in android. What I want to do is to send data from client then the server retrieves and send again to client..
For example I'm going to send the item code to my server and I will like to query something like this:
SELECT itemname FROM items WHERE itemcode = :itemcode $itemname = $result['itemname']; Where :itemcode is the data that's being passed by my client. Next, after passing the itemcode, I would like to use the itemname to include in my next query to retrieve all other records.
SELECT itemsize, itemmeasure FROM itemsdetail WHERE itemname = :itemname And so it displays all the records.
What I've tried so far, I created another table to query the last inserted data. But I think this is not efficient. I only want to put the queries in one php file.
<?php include('dbconnect.php'); $sql = "SELECT itemname FROM items ORDER BY _id DESC LIMIT 1"; $stmt = $conn->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $itemname = $result['itemname']; $sql = "SELECT itemsize, itemmeasure FROM itemsdetail AND itemname = :itemname"; $stmt = $conn->prepare($sql); $stmt->execute(array(':itemname' => $itemname)); $set = array(); while($r = $stmt->fetchAll(PDO::FETCH_ASSOC)){ $set = $r; } header('Content-type: application/json'); echo json_encode($set); ?> Java:
@Override protected Void doInBackground(Void... params) { // Create the array arraylist = new ArrayList<HashMap<String, String>>(); // Retrieve JSON Objects from the given website URL in JSONfunctions.class String result = JSONFunctions.getJSONfromURL(URL); try { JSONArray jr = new JSONArray(result); for(int i=0;i<jr.length();i++) { HashMap<String, String> map = new HashMap<String, String>(); jb = (JSONObject)jr.get(i); map.put(TAG_ITEMSIZE, jb.getString(TAG_ITEMSIZE)); map.put(TAG_ITEMMEASURE, jb.getString(TAG_ITEMMEASURE)); arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } So far I'm getting error if I put the two queries in one PHP file, I don't know what's wrong. So my alternative solution is to create another php file to receive the passed data from my client. But I know this is not a good solution. I need to be able to put it inside one php file to pass my data and use that passed data inside my second query. Do you have any ideas how to do this? Your help will be greatly appreciated. thanks.