need help with the output!

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

Locked
melchor_06
Forum Newbie
Posts: 13
Joined: Wed Feb 11, 2009 3:58 am

need help with the output!

Post by melchor_06 »

my code works perfectly fine by giving outputs of values by adding commas.

Code: Select all

 
<?php if ( $languages )  { ?>    
   <dl class="clearfix">        
       <dt>His spoken languages</dt> 
      <dd>
            <?php  
               $string = '';                            
               $i = 0;
               $total = count($languages);
                                            
               foreach ($languages as $value) {
                                                        
                    $i++;
                    $string .= $value['language'];
                                                        
                    if ( $i < $total ) { $string .= ', '; }  
                                                    
               }
                   echo $string;
            ?>
     </dd>
   </dl>
<?php } ?>
 
which for example will give an ouput like this:
 

Code: Select all

 
His spoken languages     english, chinese, french
 
 
but my problem now is if there's no data inside it with would always gives an ouput of
 

Code: Select all

 
His spoken languages
 
i need to eliminate this if there's no data inside to ouput.


thanks guys . . .
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: need help with the output!

Post by John Cartwright »

You created a new thread.. why?

Locked.
Locked