How to load data from MySQL for specific id. What I mean is when I click on gridview item 1 to load what I need for this item from MySQL. Currently I have
$objConnect = mysql_connect("localhost","user","pass");
$objDB = mysql_select_db("database");
$strSQL = "SELECT * FROM table";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
This obviously load everything from that table. But what if I want when I click on list item_1 to load some query like select * from table where clickeditem = 1
?
I guess I must post it to the .php
script but how?
I don't know which part of JAVA code is needed so please tell me if you need and I will post it. Updated: @Override protected Void doInBackground(String... params) { // TODO Auto-generated method stub
String url = "file.php";
JSONArray data;
try {
resultServer = getJSONUrl(url);
data = new JSONArray(resultServer);
MyArrList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, Object>();
map.put("id", (String)c.getString("id"));
map.put("name", (String)c.getString("name"));
map.put("price", (String)c.getString("price"));
map.put("weight", (String)c.getString("weight"));
// Thumbnail Get ImageBitmap To Bitmap
map.put("ImagePathThum", (String)c.getString("image"));
map.put("ImageThumBitmap", (Bitmap)loadBitmap(c.getString("image")));
// Full (for View Full)
map.put("ImagePathFull", (String)c.getString("image_big"));
MyArrList.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
UPDATE with sql.
$strSQL = "SELECT m.id, name, image, image_big, weight, price
FROM posts m
JOIN packet_r mr
ON m.id = mr.id
WHERE packed_id = 1";