I am working on a custom module that needs to find the next occurrence of a node by it's date field. I have spent the better part of the day trying to figure out how to perform a query that will exclude past events and find the next one coming up.
The basic code I have right now:
// query db to find next STOMP event
$type = 'stomp';
$status = 1;
$sql = "SELECT * FROM {node} n WHERE type = '%s' AND status = %d ORDER BY n.created ASC";
$result = db_query(db_rewrite_sql($sql), $type, $status);
//extract the output
while ($data = db_fetch_object($result)) {
$node = node_load($data->nid);
}
This works great but does not account for the CCK date field. I am really struggling with figuring out a way to perofmr a query that will search the 'stomp' content type and compare the CCK date field with the current date to find the next one to occur.
Any help is much, much appreciated!
Comments
Comment #1
3cwebdev commentedOkay, I figured it out :)
For reference:
Using date field as unix timestamp type.
Should this snippet be moved from the issue cue to somewhere where it might be more easily found?
Comment #2
giorgoskIf you think code is worth for the PHP snippets handbook
go ahead and create a relevant page
http://drupal.org/handbook/customization/php-snippets
Since your request was "fixed" remember to "fix" it
and please always keep a meaningful title for the content ;-)