group concat - How to combine two scripts comparing the date from input and database while it in the for loop PHP -
i have 2 php scripts. 1 script comparing date beween input (from form) , date inside mysql database. other 1 script updating the database while date still empty.
the first script :
$start = $_post['start']; //from input $end = $_post['end']; //from input $d1 = date_create($start); $d2 = date_create($end); $diff = date_diff($d1, $d2); $days = (int)$diff->format('%a'); for($i=0;$i<=$days;$i++) { $tgl = date("y-m-d", strtotime("$start +$i day")); $query = "select group_concat(name separator ', '),count(1) data '$tgl' between start , end"; $result = mysqli_query($connect, $query); list($name,$jml) = mysqli_fetch_row($result); mysqli_free_result($result); if($jml >= 2){ echo "<tr><td align='center'>$tgl</td><td align='left'>$name</td><td align='center'>$jml</td></tr>"; } }
the second script :
$query="update data set start='$start', end='$end' no = '1'" ; $result = mysqli_query($connect, $query); if($result) { echo "<script>alert('data ok.') location.replace('form.php')<script>"; } else { echo "data not ok"; }
how combine 2 scripts can run in 1 script :
there date 2017-07-01 until 2017-07-10
date 2017-07-04
until 2017-07-07
used other user
a. if input date 2017-07-04
until 2017-07-07
<-- ok, displays table data filtered. not execute update query (second script)
b. if input date 2017-07-01
until 2017-07-05
or 2017-07-06
until 2017-07-10
<-- displays table data filtered don,t execute update query (second script)
c. if input date 2017-07-01
until 2017-07-03
or 2017-07-08
until 2017-07-10
<-- empty (no user use date) execute update query (second script)
thanks answers..
Comments
Post a Comment