jgamble Posted March 4, 2010 Share Posted March 4, 2010 Hey yall, I am in the middle of creating a RSS feed for work, that is pulling data from a PSQL database and displaying it. I am having a problem getting it to display the days that I want it to though. I only want it to display events that are happening today and tomorrow, but I cannot get it to display anything unless I am showing the events that end today. Below are my two select statements. The top one works, the bottom does not. $query = "SELECT * FROM web.events WHERE date_end = '".date("m/d/Y")."' ORDER BY date_begin ASC"; $query = "SELECT * FROM web.events WHERE date_end >= '".date("m/d/Y")."' AND date_begin <= '".date("m/d/Y")."' ORDER BY date_begin ASC"; Does anyone know of a better way to do this? I don't understand why the only information that will display is when the date_end = todays date. Thanks for any help you can provide. Link to comment https://forums.phpfreaks.com/topic/194150-rss-and-php/ Share on other sites More sharing options...
schilly Posted March 4, 2010 Share Posted March 4, 2010 I think you want to use an OR in that statement $query = "SELECT * FROM web.events WHERE date_end >= '".date("m/d/Y")."' OR date_begin <= '".date("m/d/Y")."' ORDER BY date_begin ASC"; An event could start before today or tomorrow but end on these days. As well an event could start today or tomorrow but not end until after these days. Now that I look closer, even that looks wrong. I think you want this: $query = "SELECT * FROM web.events WHERE (date_end >= '".date("m/d/Y",$today)."' AND date_end <= '".date("m/d/Y",$tomorrow)."') OR (date_begin >= '".date("m/d/Y",$today)."' AND date_begin <= '".date("m/d/Y",$tomorrow)."') ORDER BY date_begin ASC"; That should get all events that either start or end today or tomorrow. I hope that's what you wanted. You will need to define $today and $tomorrow though. Link to comment https://forums.phpfreaks.com/topic/194150-rss-and-php/#findComment-1021534 Share on other sites More sharing options...
jgamble Posted March 4, 2010 Author Share Posted March 4, 2010 Thanks for your fast response. I have tried out your code and I have figured out that I messed up at the beginning. The way that date_begin and date_end are formatted is YYYY-MM-DD, and when I try to change the code to reflect that, it isn't working. I am getting the error "Invalid argument supplied for foreach(). This is the entire code $today = date("Y-m-d"); $tomorrow = mktime(0,0,0,date("Y"),date("m"),date("d")+1); //get data from table web.events $query = "SELECT * FROM web.events WHERE (date_end >= '".date("Y-m-d",$today)."' AND date_end <= '".date("Y-m-d",$tomorrow)."') OR (date_begin >= '".date("Y-m-d",$today)."' AND date_begin <= '".date("Y-m-d",$tomorrow)."') ORDER BY date_begin DESC"; $result = pg_query($query); while ($line = pg_fetch_array($result)) { $return[] = $line; } //this is the first part of the output file which shows the title and description for the entire page $output = " <title>Greater Raleigh Events</title> <link>http://www.visitraleigh.com/test/jon/jobs_test_old.php</link> <description>Upcoming events in the Greater Raleigh Area</description> <language>en-us</language> <lastBuildDate>".date("D, d M Y h:m:s T")."</lastBuildDate> <managingEditor>[email protected] (Jon Gamble)</managingEditor> <webMaster>[email protected] (Jon Gamble)</webMaster> "; // For each event in the array, it returns the title, url and description and adds it to the end of the output foreach ($return as $line) { $output .= "<item> <title>".htmlentities($line['title'])."</title> <link>".htmlentities($line['url'])."</link> <description>".$line['description']."</description> </item>"; } Link to comment https://forums.phpfreaks.com/topic/194150-rss-and-php/#findComment-1021573 Share on other sites More sharing options...
schilly Posted March 4, 2010 Share Posted March 4, 2010 likely an error in your query. $result = pg_query($query) or die(mysql_error()); try that. Link to comment https://forums.phpfreaks.com/topic/194150-rss-and-php/#findComment-1021596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.