Page 1 of 1

need help with the output!

Posted: Thu Feb 12, 2009 8:42 pm
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 . . .

Re: need help with the output!

Posted: Thu Feb 12, 2009 8:49 pm
by John Cartwright
You created a new thread.. why?

Locked.