-2

I need to fatch WEEKOFYEAR number from this php code but it's not working, please help to make it works I need use "UTC_DATE()"

 <?php

    $r11 = mysql_query("SELECT WEEKOFYEAR()  FROM `users`");
    $result = mysql_fetch_array($r11);
    $r11=$result['WEEKOFYEAR()'];
    echo $r11;

    }
    else{
    echo("error");
    }
    }
    ?>
Davit B
  • 1
  • 4
  • `WEEKOFYEAR` requires a date argument which is missing here. You should check your query errors rather than just showing the message "error" while debugging. – apokryfos Jan 27 '17 at 16:40
  • yes missing because I need use UTC_DATE() as date string and dont know how to do this... – Davit B Jan 27 '17 at 16:43
  • `WEEKOFYEAR(UTC_DATE())` and use @scaisEdge 's solution to give an alias to the column. Also remove `FROM users` you don't need it at all. – apokryfos Jan 27 '17 at 16:46
  • 1
    Why not doing it in PHP? `print date('W');` http://php.net/manual/en/function.date.php – JustOnUnderMillions Jan 27 '17 at 16:46
  • Please stop using `mysql_` functions, as [they were removed from PHP 7.0](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Jan 27 '17 at 23:16

1 Answers1

1

use an alias for function name

    $r11 = mysql_query("SELECT WEEKOFYEAR()  as WEEK_OF_YEAR FROM `users`");
    $result = mysql_fetch_array($r11);
    $r11=$result['WEEK_OF_YEAR'];
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • 1
    Please stop using `mysql_` functions, as [they were removed from PHP 7.0](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Jan 27 '17 at 23:15