0
$sqlforData = "SELECT *, `main`.`email` as useremail, `main`.`ID`  as `userID`, `mail_owners`.`country_code_field` as `micountry`, DATE(`main`.`time`) as `mrDate` FROM `main` LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID` WHERE `main`.`is_deleted` = 0 ORDER BY `main`.`ID`, DATE(`main`.`time`) DESC";

this is my query I'm fetching all the data and trying to show them by php condition like this.

while ($table = mysqli_fetch_array($result)) {
    echo strtotime($table['mrDate']) >= strtotime($from) && strtotime($table['mrDate']) <= strtotime($to);
}

but this is not showing all the data as I've more then 30k data....and I can just get half of the data from my database. and I'm also getting issues is I set the from date to Augest 1, 2018. After that this just provides me one month data even I've set the to date to November 1, 2018

M.i. Sujon
  • 9
  • 2
  • 6
  • Have you run the query directly in MySQL? Are you getting a different result than you expect there? It might be a query structure issue, and not a PHP issue. – Difster Nov 21 '18 at 13:28
  • Are you sure you getting the right value in your SQL from `DATE(\`main\`.\`time\`)`? – Nigel Ren Nov 21 '18 at 13:31
  • yes...sure...I'm getting the write value from there. But that data not sorting by this php condition – M.i. Sujon Nov 21 '18 at 13:36
  • If you are just looking to get the records back between those dates, consider using [MYSQL's BETWEEN](https://stackoverflow.com/questions/3822648/how-do-i-query-between-two-dates-using-mysql) – Nigel Ren Nov 21 '18 at 13:36
  • I've used that mysqli between...but that's not working. that's why I've used the php – M.i. Sujon Nov 21 '18 at 13:37
  • Could also anyone elaborate on the part of the query `SELECT *`? As far as I remember it will select all data from the `LEFT JOIN` result in this instanse. I have a feeling i remember it wrong. – Eugene Anisiutkin Nov 21 '18 at 13:39
  • Yes....normally the query is getting all the data from the database....but condition by php is not working. this condition is not returning values all from the database. – M.i. Sujon Nov 21 '18 at 13:40
  • Amendment, `strtotime($table['mrDate']) >= strtotime($from) && strtotime($table['mrDate']) <= strtotime($to)` always evaluates to boolean value. And echo does not output boolean values correctly. Example: doing `var_dump(strtotime("13:34") >= strtotime("13:33") && strtotime("13:34") <= strtotime("13:35"));` yealds `boolean: true` as a result. `echo strtotime("13:34") >= strtotime("13:33") && strtotime("13:34") <= strtotime("13:35"));` outputs nothing – Eugene Anisiutkin Nov 21 '18 at 14:14

0 Answers0