|
|
|
Android รบกวนผู้รู้ช่วยแนะนำเกี่ยวกับการทำปุ่ม Delete หน่อยครับ พึ่งเริ่มศึกษาใหม่ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","root","root");
$objDB = mysql_select_db("mydatabase");
// $_POST["sMemberID"] = "1"; // for Sample
$strMemberID = $_POST["sMemberID"];
$strSQL = "DELETE FROM member WHERE 1 AND MemberID = '".$strMemberID."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr["StatusID"] = "0";
$arr["Error"] = "Cannot delete data!";
}
else
{
$arr["StatusID"] = "1";
$arr["Error"] = "";
}
/**
$arr['StatusID'] // (0=Failed , 1=Complete)
$arr['Error' // Error Message
*/
mysql_close($objConnect);
echo json_encode($arr);
?>
Code
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
int menuItemIndex = item.getItemId();
String[] menuItems = Cmd;
String CmdName = menuItems[menuItemIndex];
// Check Event Command
if ("View".equals(CmdName)) {
Toast.makeText(MainActivity.this,"Your Selected View",Toast.LENGTH_LONG).show();
/**
* Call the mthod
*/
} else if ("Update".equals(CmdName)) {
Toast.makeText(MainActivity.this,"Your Selected Update",Toast.LENGTH_LONG).show();
String sMemberID = MyArrList.get(info.position).get("MemberID").toString();
String sName = MyArrList.get(info.position).get("Name").toString();
String sTel = MyArrList.get(info.position).get("Tel").toString();
Intent newActivity = new Intent(MainActivity.this,UpdateActivity.class);
newActivity.putExtra("MemberID", sMemberID);
startActivity(newActivity);
} else if ("Delete".equals(CmdName)) {
// Request to Delete data.
String url = "https://www.thaicreate.com/android/deleteData.php";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sMemberID", MyArrList.get(position).get("MemberID")));
String resultServer = getJSONUrl(url,params);
/** Get result delete data from Server (Return the JSON Code)
* StatusID = ? [0=Failed,1=Complete]
* Error = ? [On case error return custom error message]
*
* Eg Login Failed = {"StatusID":"0","Error":"Cannot delete data!"}
* Eg Login Complete = {"StatusID":"1","Error":""}
*/
String strStatusID = "0";
String strError = "Unknow Status";
try {
JSONObject c = new JSONObject(resultServer);
strStatusID = c.getString("StatusID");
strError = c.getString("Error");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Prepare Delete
if(strStatusID.equals("0"))
{
// Dialog
adb2.setTitle("Error! ");
adb2.setIcon(android.R.drawable.btn_star_big_on);
adb2.setPositiveButton("Close", null);
adb2.setMessage(strError);
adb2.show();
}
else
{
Toast.makeText(MainActivity.this, "Delete data successfully.", Toast.LENGTH_SHORT).show();
ShowData(); // reload data again
}
}
return true;
}
Android Delete data in Web Server Database (Web Server)
|
|
|
|
|
Date :
2015-09-04 09:43:16 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีสีแดงขึ้น position กับ
adb2 ครับ
adb2 นี่ต้องสร้างตัวแปรใหม่หรือเปล่า และตรงไหนครับ
แบบว่าจะให้แสดง Dialog ถามว่าต้องการลบหรือไม่ด้วยอ่ะครับ
ขอภัย ด้วยครับ ผมเป็นคนเข้าใจยากครับ
ขอบคุณคับ
|
ประวัติการแก้ไข 2015-09-04 15:42:28
|
|
|
|
Date :
2015-09-04 15:23:19 |
By :
sacool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เข้าไปอ่านเพิ่มเติมในบทความครับ
|
|
|
|
|
Date :
2015-09-04 16:08:10 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับ ขอบคุณครับ
|
|
|
|
|
Date :
2015-09-04 16:14:33 |
By :
sacool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|