Page 1 of 1

if (empty) don't want comma to print

Posted: Sun Jun 01, 2003 10:43 am
by jarow
the following prints out just fine if there is an author and year in the database for the field "subgenero". The problem is if there is no author and year in the database the "," between the two fields still prints out even though the fields are empty. Is there a way to write this so that if the author and year fields are empty the "," won't print out either.

Thanks

Code: Select all

<?php
if($row_rsspecies['subgenero']) {
   if($base_subgenero != $row_rsspecies['subgenero']) { 
      echo str_repeat("<dd>",$i++).'Subgen'. " " .$row_rsspecies['subgenero']." ".$row_rsspecies['author'].",".$row_rsspecies['year']; 
      $base_subgenero = $row_rsspecies['subgenero']; 
   } else {
      $i++;
   }
} else {
   $base_subgenero = '';
}

?>
Thanks

Posted: Sun Jun 01, 2003 5:18 pm
by McGruff
Add something like this maybe:

Code: Select all

<?php
IF (!empty($row_rsspecies['author']) AND !empty($row_rsspecies['year']) {

    $separator = ', ';

} ELSE {

    $separator = '';

}

// .. the echo line would be:

echo str_repeat("<dd>",$i++) . 'Subgen' .  " " . $row_rsspecies['subgenero'] . " " . $row_rsspecies['author'] . $separator . $row_rsspecies['year']; 

?>

Posted: Mon Jun 02, 2003 4:19 am
by jarow
thanks McGruff...worked real well