[PHP] Avoiding blank lines in HTML when field is empty

2003-10-23 Thread Robb Kerr
I'm a PhP /MySQL newbie so please excuse the simple question. I'm returning
results from a MySQL query on a webpage. My code includes...

td valign=top
  ?php echo $row_rsVandyDivAddresses['First_Name']; ? ?php echo
$row_rsVandyDivAddresses['Last_Name'];?, ?php echo
$row_rsVandyDivAddresses['Degree']; ?
  br
  ?php echo $row_rsVandyDivAddresses['Address']; ?
  br
  ?php echo $row_rsVandyDivAddresses['City']; ?, ?php echo
$row_rsVandyDivAddresses['State']; ??php echo
$row_rsVandyDivAddresses['Zip']; ?
  br
  Phone: ?php echo $row_rsVandyDivAddresses['Phone']; ?
  br
  Email: ?php echo $row_rsVandyDivAddresses['Email']; ?
/td

Here's the problem. Some of the fields are empty (for instance 'Address')
and the way my code is configured a blank line appears in the returned data
when the field is empty. How do I change this code to add a conditional that
only echos the field contents AND the br when the field is NOT empty?

I've tried...

  ?php if (!empty($row_rsVandyDivAddresses['Address']) echo
$row_rsVandyDivAddresses['Address']); ?

but don't know how to include the line break br in the if statement.

Any help is greatly appreciated,
Robb

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Avoiding blank lines in HTML when field is empty

2003-10-23 Thread Chris Shiflett
--- Robb Kerr [EMAIL PROTECTED] wrote:
 Here's the problem. Some of the fields are empty (for instance
 'Address') and the way my code is configured a blank line appears in
 the returned data when the field is empty. How do I change this code
 to add a conditional that only echos the field contents AND the br
 when the field is NOT empty?

if (!empty($foo))
{
 echo $foo . 'br /';
}

Hope that helps.

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Avoiding blank lines in HTML when field is empty

2003-10-23 Thread Jordan S. Jones
Robb,

You pretty much have it.. Here is what you will most likely want:

?php
if (!empty($row_rsVandyDivAddresses['Address'])  strlen (trim ($row_rsVandyDivAddresses['Address']))  0)
{
	echo $row_rsVandyDivAddresses['Address']) . 'br'; 
}
?

Feel free to format as you wish.

Jordan S. Jones



Robb Kerr wrote:

I'm a PhP /MySQL newbie so please excuse the simple question. I'm returning
results from a MySQL query on a webpage. My code includes...
 

[snip]

I've tried...

 ?php if (!empty($row_rsVandyDivAddresses['Address']) echo
$row_rsVandyDivAddresses['Address']); ?
but don't know how to include the line break br in the if statement.

Any help is greatly appreciated,
Robb
 

--
I am nothing but a poor boy. Please Donate..
https://www.paypal.com/xclick/business=list%40racistnames.comitem_name=Jordan+S.+Jonesno_note=1tax=0currency_code=USD
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Avoiding blank lines in HTML when field is empty

2003-10-23 Thread Eugene Lee
On Thu, Oct 23, 2003 at 12:46:29PM -0500, Robb Kerr wrote:
: 
: I'm a PhP /MySQL newbie so please excuse the simple question. I'm returning
: results from a MySQL query on a webpage. My code includes...
: 
: td valign=top
:   ?php echo $row_rsVandyDivAddresses['First_Name']; ? ?php echo
: $row_rsVandyDivAddresses['Last_Name'];?, ?php echo
: $row_rsVandyDivAddresses['Degree']; ?
:   br
:   ?php echo $row_rsVandyDivAddresses['Address']; ?
:   br
:   ?php echo $row_rsVandyDivAddresses['City']; ?, ?php echo
: $row_rsVandyDivAddresses['State']; ??php echo
: $row_rsVandyDivAddresses['Zip']; ?
:   br
:   Phone: ?php echo $row_rsVandyDivAddresses['Phone']; ?
:   br
:   Email: ?php echo $row_rsVandyDivAddresses['Email']; ?
: /td
: 
: Here's the problem. Some of the fields are empty (for instance 'Address')
: and the way my code is configured a blank line appears in the returned data
: when the field is empty. How do I change this code to add a conditional that
: only echos the field contents AND the br when the field is NOT empty?

Make a wrapper function instead that does the proper tests:

function print_field($field)
{
if (!empty($field))
{
echo $field . br\n;
}
}

Then change your code a bit:

td valign=top
?php echo $row_rsVandyDivAddresses['First_Name']; ?
?php echo $row_rsVandyDivAddresses['Last_Name']; ?,
?php print_field $row_rsVandyDivAddresses['Degree']; ?
?php print_field $row_rsVandyDivAddresses['Address']; ?
?php echo $row_rsVandyDivAddresses['City']; ?,
?php echo $row_rsVandyDivAddresses['State']; ?
?php echo $row_rsVandyDivAddresses['Zip']; ?
br
Phone: ?php print_field $row_rsVandyDivAddresses['Phone']; ?
Email: ?php print_field $row_rsVandyDivAddresses['Email']; ?
/td

You get the idea.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php