Page 1 of 1

Working on an RSS file, need help with an IF statement...

Posted: Sat Nov 07, 2009 11:56 pm
by craigwg
Here is my situation. I have a table that looks something like this:

title date
-------------------------------
Gravity 01/08/2009
Science 02/15/2009
04/01/2009
Tech 05/05/2009
.
.
. (etc)


Notice that some entries have titles, some do not. ALL have a date.

So in my RSS feed I need a basic if statement that says, "If the title is present, use that as the title. Otherwise use the date as the title. For some reason in the database the title field is marked as blank, '', instead of being NULL.

Simple, no? But my little code isn't working! Here is what I have:

Code: Select all

 
if (strlen($_GET['title'])>1) {                             # if the length is greater than one
  echo  "<title>".$row['titledate']."</title>\n";      # Display the date value
} else {                                                        # Otherwise...
  echo  "<title>".$row['title']."</title>\n";            # Display the title value
}
 
strlen doesn't work. I've tried empty, is_null and a few others. Can someone help me out?

Thanks!
Craig

Re: Working on an RSS file, need help with an IF statement..

Posted: Sun Nov 08, 2009 12:19 am
by McInfo

Code: Select all

if (strlen($_GET['title']) > 1)
It looks like you should be testing $row['title'] for a string length greater than zero. (two changes)

Code: Select all

if (strlen($row['title']) > 0)
Edit: This post was recovered from search engine cache.

Re: Working on an RSS file, need help with an IF statement...

Posted: Sun Nov 08, 2009 8:46 pm
by craigwg
I beleive it was Socrates who stated so vividly, "DOH!"

Thanks man! Full worky worky.
Craig