0

I'm trying to sort my photos by hour and minute but it will not catch the minutes - it's just keep saying that nothing exists for that hour and minute. If I'm trying to sort only after the hours, it works perfectly. I have tested WHERE DATEPART(minute, exif_taken) = "'.$_GET['min'].'" but I'm keep getting the following error message:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION gallery.DATEPART does not exist' in ...

I'm using WAMP Server with default settings except for some modules activated for both Apache and PHP like mod_rewrite and php_exif. Here's how my SQL query looks like:

SELECT *
FROM photos
WHERE HOUR(exif_taken) = "'.$_GET['h'].'"
AND MINUTE(exif_taken) = "'.$_GET['min'].'"
ORDER BY exif_taken DESC

$_GET['h'] is the hour and $_GET['min'] the minute.

How can I solve my problem?

Thanks in advance.

Airikr
  • 6,258
  • 15
  • 59
  • 110

2 Answers2

0

Are you using MySQL? If true, DATEPART() function doesn't exist. You shoul use MINUTE() function..

Here is the complete documentation.

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

BTW, for god sake, sanitize your _GET vars before send to the SQL query. You are exposing your system to SQL Injections.

Babblo
  • 794
  • 5
  • 17
  • Yes. I'm using MySQL and I am using just that - `MINUTE()`. But it doesn't work as I wanted it to work. It just keeps saying that the specific minute does not exists in my database but it does! Sanitize my _GET variables? Many thanks :) I haven't think about that before. – Airikr Mar 06 '13 at 23:52
0

In some odd way it's working perfectly now with the SQL query I posted in my question O.o

Airikr
  • 6,258
  • 15
  • 59
  • 110