Php 如何在mysql中存储动态生成的复选框的详细信息
我正在尝试在android上制作考勤应用程序。当用户进入编辑文本组件中的部分时,学生列表将从mysql数据库中动态生成,并带有复选框(复选框没有id)已选中。当用户取消选中复选框时,学生必须存储为缺席,否则学生必须存储为出席。有人可以帮助我如何实现在mysql数据库中存储复选框(即,出席或缺席)详细信息的代码吗 提前谢谢Php 如何在mysql中存储动态生成的复选框的详细信息,php,android,mysql,Php,Android,Mysql,我正在尝试在android上制作考勤应用程序。当用户进入编辑文本组件中的部分时,学生列表将从mysql数据库中动态生成,并带有复选框(复选框没有id)已选中。当用户取消选中复选框时,学生必须存储为缺席,否则学生必须存储为出席。有人可以帮助我如何实现在mysql数据库中存储复选框(即,出席或缺席)详细信息的代码吗 提前谢谢 public class main extends ListActivity implements android.widget.CompoundButton.OnChecke
public class main extends ListActivity implements android.widget.CompoundButton.OnCheckedChangeListener {
SQLiteDatabase dBase;
private CheckBox checkBox1
ListView lv;
ArrayList<Student>studentList;
StudentAdapter slAdapter;
private Context context;
String returnString;
private String URL_ITEMS;
private String section;
ProgressDialog progressdialog;
private static final String TAG_FIXTURE = "fixture";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
JSONArray matchFixture = null;// to store the result of MySQL query after decoding JSON
ArrayList<HashMap<String, String>> matchFixtureList = new ArrayList<HashMap<String, String>>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// GET THE DATA FROM OLD INTENT
Intent previous = getIntent();
section = previous.getStringExtra("section");
Log.i("Section: ", " " + section);
// Now generate the URL
URL_ITEMS = "http://10.0.2.2/attend/getFixture.php?section=" + section;
new GetFixture().execute();
}
// declare parameters that are passed to PHP script i.e. the name "section" and its value submitted by user
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
private class GetFixture extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressdialog = new ProgressDialog(main.this);
progressdialog.setTitle("Please Wait");
progressdialog.setMessage("Getting Information from Server");
progressdialog.setCancelable(false);
progressdialog.show();
}
@Override
protected Void doInBackground(Void... arg) {
ServiceHandler serviceClient = new ServiceHandler();
Log.d("url: ", "> " + URL_ITEMS);
String json = serviceClient.makeServiceCall(URL_ITEMS,ServiceHandler.GET);
// print the json response in the log
Log.d("main.class", " Get match fixture response: > " + json);
if (json != null) {
try {
Log.d("try", "in the try");
JSONObject jsonObj = new JSONObject(json);
Log.d("jsonObject", "new json Object");
// Getting JSON Array node
matchFixture = jsonObj.getJSONArray(TAG_FIXTURE);
Log.d("json aray", "user point array");
int len = matchFixture.length();
Log.d("len", "get array length");
if(matchFixture.length() == 0) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(main.this, "No Data Available for Section " + section, Toast.LENGTH_SHORT).show();
}
});
}
for (int i = 0; i < matchFixture.length(); i++) {
JSONObject c = matchFixture.getJSONObject(i);
String id = c.getString(TAG_ID);
Log.d("id", id);
String name = c.getString(TAG_NAME);
Log.d("name", name);
// hashmap for single match
HashMap<String, String> matchFixture = new HashMap<String, String>();
// adding each child node to HashMap key => value
matchFixture.put(TAG_ID, id);
matchFixture.put(TAG_NAME, name);
matchFixtureList.add(matchFixture);
}
}
catch (JSONException e) {
Log.d("catch", "in the catch");
e.printStackTrace();
}
}
else {
Log.e("JSON Data", "Didn't receive any data from server!");
Toast.makeText(main.this, "Check Internet Connection", Toast.LENGTH_SHORT).show();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
ListAdapter adapter = new SimpleAdapter(
main.this, matchFixtureList,
R.layout.list1_item, new String[] {
TAG_ID, TAG_NAME }
, new int[] {
R.id.id,R.id.name
}
);
setListAdapter(adapter);
// lv.setAdapter(adapter);
//lv.setAdapter(slAdapter);
if(progressdialog.isShowing()) {
progressdialog.dismiss();
}
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(main.this, "into the on checked change listener..", Toast.LENGTH_SHORT).show();
int pos = lv.getPositionForView(buttonView);
if(pos !=ListView.INVALID_POSITION){
for (int i = 0; i < matchFixture.length(); i++) {
JSONObject c = null;
try {
c = matchFixture.getJSONObject(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String id = null;
try {
id = c.getString(TAG_ID);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String name = null;
try {
name = c.getString(TAG_NAME);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SQLiteDatabase database = openOrCreateDatabase("ORCL", MODE_PRIVATE, null);
database.execSQL("CREATE TABLE IF NOT EXISTS attendance(id integer primary key autoincrement,name VARCHAR(150),id INT(10)");
database.execSQL("INSERT INTO attendance(name,id) VALUES('" + name + "'," + id+");");
Toast.makeText(main.this, "record inserted..", Toast.LENGTH_SHORT).show();
database.close();
}
}
}
/** You can not insert empty values and you should create Database and tables first **/
//ContentValues values= new ContentValues();
// dBase.insert("attendance", null, values);
// Toast.makeText(getApplicationContext(), "Record Inserted..", 2000).show();
public类主扩展ListActivity实现android.widget.CompoundButton.OnCheckedChangeListener{
sqlitedbase;
专用复选框复选框1
ListView lv;
ArrayListstudentList;
学生适配器;
私人语境;
字符串返回字符串;
私有字符串URL_项;
私有字符串部分;
进行对话进行对话;
私有静态最终字符串标记_FIXTURE=“FIXTURE”;
私有静态最终字符串标记\u ID=“ID”;
私有静态最终字符串标记_NAME=“NAME”;
JSONArray matchFixture=null;//解码JSON后存储MySQL查询结果
ArrayList matchFixtureList=新建ArrayList();
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//从旧的意图中获取数据
Intent previous=getIntent();
截面=上一个.getStringExtra(“截面”);
日志i(“章节:”、“+”章节);
//现在生成URL
URL_项目=”http://10.0.2.2/attend/getFixture.php?section=“+节;
新建GetFixture().execute();
}
//声明传递给PHP脚本的参数,即用户提交的名称“section”及其值
ArrayList后参数=新的ArrayList();
私有类GetFixture扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
progressdialog=新建progressdialog(main.this);
progressdialog.setTitle(“请稍候”);
progressdialog.setMessage(“从服务器获取信息”);
progressdialog.setCancelable(假);
progressdialog.show();
}
@凌驾
受保护的Void doInBackground(Void…arg){
ServiceHandler serviceClient=新的ServiceHandler();
Log.d(“url:”,“>”+url\u项);
字符串json=serviceClient.makeServiceCall(URL\u项,ServiceHandler.GET);
//在日志中打印json响应
Log.d(“main.class”,“获取匹配夹具响应:>”+json);
if(json!=null){
试一试{
Log.d(“尝试”、“在尝试中”);
JSONObject jsonObj=新的JSONObject(json);
d(“jsonObject”,“新json对象”);
//获取JSON数组节点
matchFixture=jsonObj.getJSONArray(TAG_FIXTURE);
Log.d(“json aray”,“用户点数组”);
int len=matchFixture.length();
Log.d(“len”,“获取数组长度”);
if(matchFixture.length()==0){
runOnUiThread(新的Runnable(){
公开募捐{
Toast.makeText(main.this,“节无可用数据”+节,Toast.LENGTH_SHORT.show();
}
});
}
对于(int i=0;ivalue
匹配夹具。放置(标签号,ID);
匹配夹具。放置(标签名称、名称);
matchFixtureList.add(matchFixture);
}
}
捕获(JSONException e){
Log.d(“捕获”、“捕获中”);
e、 printStackTrace();
}
}
否则{
e(“JSON数据”,“没有从服务器接收任何数据!”);
Toast.makeText(main.this,“检查互联网连接”,Toast.LENGTH_SHORT.show();
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
ListAdapter=新的SimpleAdapter(
main.this,matchFixtureList,
R.layout.list1_项,新字符串[]{
标记\标识,标记\名称}
,new int[]{
R.id.id,R.id.name
}
);
setListAdapter(适配器);
//低压设置适配器(适配器);
//低压设置适配器(slAdapter);
if(progressdialog.isShowing()){
progressdialog.disclose();
}
}
}
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
Toast.makeText(main.this,“插入已选中的更改侦听器…”,Toast.LENGTH_SHORT.show();
int pos=lv.getPositionForView(按钮视图);
如果(位置!=列表视图。位置无效){
对于(int i=0;i // set the ID before rendering
chcekbox.setTag(ID);
// get the ID when this method called "onCheckedChanged"(before storing into the database)
buttonView.getTag();