Display Number of Times X Value is Empty

Thread Solved

Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Display Number of Times X Value is Empty

 
0
  #1
Sep 8th, 2009
Hello,

I am retrieving results from a RSS feed, but not all results have a title. I would like to run something like the below code which, lets me know how many times a title is empty.

If three "titles" are empty, then X code would dynamically echo "3" etc....

Not sure if a foreach would work... Thanks in advance!

  1. <?php
  2. if(empty($title)){
  3. //Code for displaying how many times "$title" is empty
  4.  
  5. } else {
  6.  
  7. echo $title;
  8.  
  9. }
  10. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 794
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Display Number of Times X Value is Empty

 
1
  #2
Sep 8th, 2009
So is $title the title of a single RSS feed item? If so, you can do something like:
  1. $count = 0;
  2. foreach($rssFeedItems as $title)
  3. {
  4. if(empty($title))
  5. echo ++$count; // a prepend increment will add one to $count before it is used
  6. else
  7. echo $title;
  8. }
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

Tags
emptydisplayvalue

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC