php - Android, MySQL, JSON: MySQL script only returning values row date is 0000-00-00 -
i working on system android devices connected wamp server. i'm trying return rows depending on date user selects in android app. must default values of date 0000-00-00, these values can updated real date. problem if select in device return rows date 0000-00-00 works. if select return rows depening on real date (e.g. 2013-08-08), not work (0 rows affected). thought format problem log shows should be.
i dont know if clear.
i copy code below in case may help.
php (date called 'fecha')
<?php // array json response $response = array(); // include db connect class require_once __dir__ . '/db_connect.php'; $db = new db_connect(); $fecha = $_get['fecha']; $result = mysql_query("select *from resultados2 fecha = $fecha") or die(mysql_error()); if (mysql_num_rows($result) > 0) { $response["resultado"] = array(); while ($row = mysql_fetch_array($result)) { // temp user array $resultado = array(); $resultado["id"] = $row["id"]; $resultado["nombre"] = $row["nombre"]; $resultado["tablet"] = $row["tablet"]; $resultado["fecha"] = $row["fecha"]; array_push($response["resultado"], $resultado); } $response["success"] = 1; $response["message"] = "returned"; echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "error"; echo json_encode($response); } ?>
android
public class monitfecha extends listactivity { private progressdialog pdialog; // creating json parser object jsonparser jsonparser = new jsonparser(); baseadapter adapter; arraylist<hashmap<string, string>> detalleslist; // url products list private static string url_detalles = "http://10.0.0.13/subida/get_fecha_d.php"; // json node names private static final string tag_success = "success"; private static final string tag_dni = "dni"; private static final string tag_id = "id"; private static final string tag_nombre = "nombre"; private static final string tag_fecha = "fecha"; private static final string tag_tablet = "tablet"; private static final string tag_correctas = "correctas"; private static final string tag_errores = "errores"; edittext txtname, txtprice, txtdesc; jsonarray resultados = null; string fecha; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fecha_candidatos); strictmode.threadpolicy policy = new strictmode. threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); boolean isreachable = false; try{ isreachable = inetaddress.getbyname("10.0.0.13").isreachable(200); } catch (exception e){ log.e("inetaddress", e.getmessage()); }finally { if (isreachable) { intent = getintent(); fecha = i.getstringextra("fecha"); new cargardetalles().execute(); }else{ toast.maketext(getapplicationcontext(), r.string.errorserver, toast.length_long).show(); } } setlistadapter(adapter); detalleslist = new arraylist<hashmap<string, string>>(); listview lv = getlistview(); lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string idd = ((textview) view.findviewbyid(r.id.id)).gettext() .tostring(); intent in = new intent(getapplicationcontext(), monitdetail2.class); in.putextra("id", idd); startactivityforresult(in, 100); } }); } class cargardetalles extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(monitfecha.this); pdialog.setmessage("actualizando..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } protected string doinbackground(string... args) { try { monitorizar(); } catch (exception e) { // todo auto-generated catch block e.printstacktrace();} return null; } protected void onpostexecute(string file_url) { pdialog.dismiss(); runonuithread(new runnable() { public void run() { adapter = new simpleadapter( monitfecha.this, detalleslist, r.layout.list_fecha, new string[] {tag_id, tag_nombre, tag_tablet, tag_fecha}, new int[] {r.id.id, r.id.nombre, r.id.tablet, r.id.fecha}); adapter.notifydatasetchanged(); setlistadapter(adapter); } }); } } public void monitorizar() throws exception{ try { list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("fecha",fecha)); jsonobject json = jsonparser.makehttprequest(url_detalles, "get", params); log.d("params", string.valueof(params)); arraylist<hashmap<string, string>> temp; temp = new arraylist<hashmap<string, string>>(); int success = json.getint(tag_success); if (success == 1) { resultados = json.getjsonarray("resultado"); (int = 0; < resultados.length(); i++) { jsonobject c = resultados.getjsonobject(i); string id = c.getstring(tag_id); string nombre = c.getstring(tag_nombre); string tablet = c.getstring(tag_tablet); string fecha = c.getstring(tag_fecha); hashmap<string, string> map = new hashmap<string, string>(); map.put(tag_id, id); map.put(tag_nombre, nombre); map.put(tag_tablet, tablet); map.put(tag_fecha, fecha); temp.add(map); detalleslist = temp; } } } catch (jsonexception e) { e.printstacktrace(); } } }
thank you
try where fecha = '$fecha'
(notice '
).
mysql 'recognize' value of $fecha
'value' instead of e.g. column name.
Comments
Post a Comment