Jump to content

RSS and PHP


jgamble

Recommended Posts

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
Share on other sites

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
Share on other sites

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>jgamble@visitRaleigh.com (Jon Gamble)</managingEditor>
                    <webMaster>jgamble@visitRaleigh.com (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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.