Getting a different result while executing THE SAME query on PHP and MYSQL!

Here is my code:
**The result of the query directly on Mysql (I’m using Navicat) is working fine. **
**but using this code above it gives ‘0’ **

$result_rap=mysqli_query($conn , "SELECT count(*) AS  total FROM articles
WHERE   STR_TO_DATE(date_rapport, '%d-%m-%Y') >=  STR_TO_DATE( '$day_rapport1' , '%d-%m-%Y')
AND  STR_TO_DATE(date_rapport, '%d-%m-%Y') <=  STR_TO_DATE( '$day_rapport2' , '%d-%m-%Y')
AND (articles.theme = 'Analphabétisme'
OR articles.theme =  'Alphabétisation'
OR articles.theme =  'Analphabète')" );

while ($data_rap=mysqli_fetch_assoc($result_rap)) {
   echo "Total pages ".$data_rap['total'];
}

What are the values in $day_report1 and $day_report2?

1 Like

hi @rpkamp,
this two variables, I’m getting them from the URL like so >>

$day_rapport1= (string)$_GET["daystart"];
$day_rapport2= (string)$_GET["dayend"];

What’re the values of the variables?

1 Like

Hi @Dormilich
They are dates in string format !
eg : $day_rapport1 = ‘08-11-2018’

-here is the “echo” of the sql query :

	SELECT count(*) AS total FROM articles WHERE STR_TO_DATE(date_rapport, '%d-%m-%Y') >= STR_TO_DATE( '08-11-2018' , '%d-%m-%Y') AND STR_TO_DATE(date_rapport, '%d-%m-%Y') <= STR_TO_DATE( '08-11-2018' , '%d-%m-%Y') AND (articles.theme = 'Analphabétisme' OR articles.theme = 'Alphabétisation' OR articles.theme = 'Analphabète')

thanks

Encoding issue with the way the search strings are typed into the PHP code, perhaps? Would they not be better encoded in some way and stored in a separate table, or do they not repeat sufficiently for that?

1 Like

yes @droopsnoot , Issue is fixed , finally i discovered that the special characters like “é” are blocking the query from being executed on the server, i used this encoding types >>

  $con->query('SET NAMES utf8');
  $con->query('SET CHARACTER utf8');

thanks

While you’re at it, you should go for utf8mb4 instead :slightly_smiling_face:

https://mathiasbynens.be/notes/mysql-utf8mb4

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.