Page 1 of 1

echo statements to leave no blank lines

Posted: Mon Apr 05, 2004 5:13 am
by jarow
Am very new to php. I have the following php echo statements:
<p><?php echo $row_cv['institucion']; ?></p>
<p><?php echo $row_cv['department']; ?></p>
<p><?php echo $row_cv['department2']; ?></p>
<p><?php echo $row_cv['address']; ?></p>
<p><?php echo $row_cv['city']; ?>, <?php echo $row_cv['country']; ?>.&nbsp; <?php echo $row_cv['postalcode']; ?></p>

How can a write a statement that in the case that there is no department or department2 that it wouldn't leave a blank line, that everything would move "up", so to speak.

Thanks for your help.

Posted: Mon Apr 05, 2004 5:26 am
by andre_c
do this for each one:

Code: Select all

<?
if ($row_cv['institution']!='') echo "<p>$row_cv[institution]</p>\n";
?>

Posted: Mon Apr 05, 2004 6:15 am
by jarow
thanks, that works...but how can I get the following to appear on the same line:

if ($row_cv['city']!='') echo "<p>$row_cv[city].</p>";
if ($row_cv['country']!='') echo "<p>&nbsp;$row_cv[country]&nbsp;</p>";
if ($row_cv['postalcode']!='') echo "<p>$row_cv[postalcode]</p>";