Интересно, как получить timeIn, у которого есть min id и timeOut, который имеет максимальный id от MySQL
php до android?
Это таблица work_Details (id, project, percent, timeIn, timeOut, twd). Теперь я хочу получить timeIn : 12:26:00
и timeOut 11:26:00
public void RetrieveTotalHours( final String ID) // Assume ID is 69 { class GetHours extends AsyncTask<Void,Void,String> { ProgressDialog loading; @Override protected void onPreExecute() { super.onPreExecute(); loading = ProgressDialog.show(getActivity(),"Fetching...","Wait...",false,false); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); loading.dismiss(); showHours(s); } @Override protected String doInBackground(Void... params) { RequestHandler rh = new RequestHandler(); String s = rh.sendGetRequestParam(Configs.RETRIEVE_HOURS,ID); return s; } } GetHours ge = new GetHours(); ge.execute(); } private void showHours(String json) { try { JSONArray array=new JSONArray(json); JSONObject jsonObject = array.getJSONObject(array.length()-1); String MiNtimeIn = jsonObject.optString(Configs.TAG_IN); String MaXtimeOut=jsonObject.optString(Configs.TAG_OUT); Log.e("A",MiNtimeIn); Log.e("S", MaXtimeOut); //total.setText(MiNtimeIn); } catch (JSONException e) { e.printStackTrace(); } }
PHP
<?php define('HOST','127.0.0.1:3307'); define('USER','root'); define('PASS',''); define('DB','androiddb'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect'); $twd= $_GET['id']; $sql = "select timeIn, timeOut from work_details WHERE twd = '".$twd."' AND id IN (SELECT MIN(id) FROM work_details WHERE twd ='".$twd."' UNION SELECT MAX(id) FROM work_details WHERE twd='".$twd."')"; $res = mysqli_query($con,$sql); $result=array(); while($row=mysqli_fetch_array($res)){ array_push($result,array('timeIn'=>$row[0],'timeOut'=>$row[1])); } echo json_encode($result); mysqli_close($con); ?>
в<?php define('HOST','127.0.0.1:3307'); define('USER','root'); define('PASS',''); define('DB','androiddb'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect'); $twd= $_GET['id']; $sql = "select timeIn, timeOut from work_details WHERE twd = '".$twd."' AND id IN (SELECT MIN(id) FROM work_details WHERE twd ='".$twd."' UNION SELECT MAX(id) FROM work_details WHERE twd='".$twd."')"; $res = mysqli_query($con,$sql); $result=array(); while($row=mysqli_fetch_array($res)){ array_push($result,array('timeIn'=>$row[0],'timeOut'=>$row[1])); } echo json_encode($result); mysqli_close($con); ?>
-<?php define('HOST','127.0.0.1:3307'); define('USER','root'); define('PASS',''); define('DB','androiddb'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect'); $twd= $_GET['id']; $sql = "select timeIn, timeOut from work_details WHERE twd = '".$twd."' AND id IN (SELECT MIN(id) FROM work_details WHERE twd ='".$twd."' UNION SELECT MAX(id) FROM work_details WHERE twd='".$twd."')"; $res = mysqli_query($con,$sql); $result=array(); while($row=mysqli_fetch_array($res)){ array_push($result,array('timeIn'=>$row[0],'timeOut'=>$row[1])); } echo json_encode($result); mysqli_close($con); ?>
Неверный выход
01-12 12:43:41.540 22692-22692/com.example.project.myapplication E/A﹕ 20:26:00 01-12 12:43:41.540 22692-22692/com.example.project.myapplication E/S﹕ 11:26:00
Он извлекает timeIn и timeOut с максимальным id …