0

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);
Vineet Jain
  • 1,515
  • 4
  • 21
  • 31
rangaraj seo
  • 31
  • 2
  • 8
  • thank you but it return as same error – rangaraj seo Dec 08 '17 at 07:03
  • Why are you using sprintf if you don't have variables to print on the string? Try this $selectorders="SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%d-%m-%y') as horo FROM userlogin WHERE type='user' ORDER BY horo DESC"; – Mauricio Florez Dec 08 '17 at 07:03
  • what's the error? – Danyal Sandeelo Dec 08 '17 at 07:09
  • 2
    **The `mysql` PHP extension is dead** -- Stop using the [`mysql` PHP extension](http://php.net/manual/en/function.mysql-connect.php). It is old, deprecated since PHP 5.5 and completely removed in PHP 7.0. Use [`mysqli`](http://php.net/manual/en/book.mysqli.php) or [`PDO_mysql`](http://php.net/manual/en/ref.pdo-mysql.php) instead. Read the answers to [this question](https://stackoverflow.com/q/12859942/4265352) to learn more about why and how. – axiac Dec 08 '17 at 07:12
  • Sprintf look at the string in first argument and replace every letters preceded by '%' by other arguments. Either you escape %, or you realize you don't have any variable to bind so sprintf is useless – Zyigh Dec 08 '17 at 08:06

1 Answers1

2

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.