rangaraj seo
rangaraj seo

Reputation: 31

order by str_to_date query return error while using php

I have created a query it was working perfectly on phpmyadmin

SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%d-%m-%y') as horo FROM userlogin WHERE type='user' ORDER BY horo  DESC

but when I pass this query on PHP return error as query was empty my PHP code is

$selectorders=sprintf("SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%d-%m-%y') as hor FROM userlogin WHERE type='user' ORDER BY horo  DESC");
$myorderquery = mysql_query($selectorders) or die(mysql_error());
$row_rsselect = mysql_fetch_assoc($myorderquery);

Upvotes: 0

Views: 46

Answers (1)

Romain Ciaccafava
Romain Ciaccafava

Reputation: 114

You are using sprintf for no reason. Since your date format use '%' characters, you need to double them if you want to use this function anyway :

$selectorders=sprintf("SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%%d-%%m-%%y') as hor FROM userlogin WHERE type='user' ORDER BY horo  DESC");

Just use a string declaration and it will work.

Upvotes: 2

Related Questions