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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
craigwg
Forum Newbie
Posts: 23
Joined: Tue Nov 03, 2009 7:48 pm

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

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
Last edited by McInfo on Thu Jun 17, 2010 1:47 pm, edited 1 time in total.
craigwg
Forum Newbie
Posts: 23
Joined: Tue Nov 03, 2009 7:48 pm

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

Post by craigwg »

I beleive it was Socrates who stated so vividly, "DOH!"

Thanks man! Full worky worky.
Craig
Post Reply