PHP MYSQL date range missed days -


in db, there 26th , 31st days not changing ok. getting 3rd day , change ok.

where wrong in code?

code:

*$from   = date("y-m-01");  $to     = date("y-m-t"); // last day current month $query  = "select date tbl_data date between '$from' , '$to' order date desc"; $result = mysqli_query($mysqli,$query); while ($row  = mysqli_fetch_array($result, mysql_assoc)) {     $date =  date_create_from_format('y-m-d', $row['date']); } $cursor =  date_create_from_format('y-m-d', $from); $finish =  date_create_from_format('y-m-d', $to); while ($cursor != $date)     {         echo date_format($cursor,'y-m-d') . "--- missed <br>";         date_modify($cursor, '+1 day');               while($cursor == $date)                 {                     echo date_format($date,'y-m-d') . "--- ok <br>";                     date_modify($cursor, '+1 day');                  }             while($cursor > $finish)                 {                     die();                 }    }* 

output:

2016-07-01--- missed
2016-07-02--- missed
2016-07-03--- ok
2016-07-04--- missed
2016-07-05--- missed
2016-07-06--- missed
2016-07-07--- missed
2016-07-08--- missed
2016-07-09--- missed
2016-07-10--- missed
2016-07-11--- missed
2016-07-12--- missed
2016-07-13--- missed
2016-07-14--- missed
2016-07-15--- missed
2016-07-16--- missed
2016-07-17--- missed
2016-07-18--- missed
2016-07-19--- missed
2016-07-20--- missed
2016-07-21--- missed
2016-07-22--- missed
2016-07-23--- missed
2016-07-24--- missed
2016-07-25--- missed
2016-07-26--- missed
2016-07-27--- missed
2016-07-28--- missed
2016-07-29--- missed
2016-07-30--- missed
2016-07-31--- missed

your question hard understand far understand, you're trying check whether there record iterated date or not.

the main point missed out is, storing single date on $date variable. clarify;

while ($row  = mysqli_fetch_array($result, mysql_assoc)) {     $date =  date_create_from_format('y-m-d', $row['date']); }  /* @ point of code, variable $date equal 2016-07-03 * because sorted existing dates in descending order , last record 2016-07-03 */ 

after code portion, "ok" check valid "2016-07-03". correct code, should have array store days , use in_array() function check existence.

another alternative applying these procedures inside while loop after changing order direction. if 2 consecutive records not consecutive days, fill these gap (second level) iteration.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -