Page 1 of 1

how to get max date from database table

Posted: Mon Sep 17, 2007 10:29 pm
by qumar
pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi,
please give some idea how to get max picture. i am uploading images under event id. each event id has more dates. i want display the max date image under event id. give some idea. i am using following query.

[syntax="php"]<?php
$result = mysql_query("SELECT * FROM maaking_pictures WHERE event_id=$event_id ORDER BY picture_id DESC limit $nexlimit,$users_per_page");
?>
thanks,
qumar.


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Sep 18, 2007 7:07 am
by mezise
Hi,
you are not very specific about the problem. If I get it right you have a table maaking_pictures with event_id field and e.g. date_of_picture field. If you want to select last picture during given event you may use a query like this:

Code: Select all

SELECT * FROM `maaking_pictures`
WHERE `event_id` = [$event_id]
ORDER BY `date_of_picture` DESC
LIMIT 1;
Michal

Posted: Tue Sep 18, 2007 10:40 am
by pickle
The MySQL function MAX() might be quicker.

Posted: Tue Sep 18, 2007 11:26 am
by mezise
Or not...