Forum Moderators: coopster

Message Too Old, No Replies

Echo null

Not echo null values

         

bbunny

3:10 pm on Nov 20, 2007 (gmt 0)

10+ Year Member



I have a textarea with a list of email addresses and not all email addresses have values, so the table fields that are 'null' produce empty spaces by using echo. How to avoid the empty spaces?
Can i accomplish by the sql or php?

Code below:

"SELECT DISTINCT email, email2, email3 FROM customers LEFT JOIN email_cust ON email_cust.email_ID = customers.customer_ID LEFT JOIN state_cust ON state_cust.state_ID = customers.customer_ID WHERE state LIKE '%%%s%%'"

<textarea name="email" cols="40" rows="10" id="email" type="text"><?php do {?><?php echo $row_record1['email']."\n", $row_record1['email2']."\n", $row_record1['email3']."\n"?><?php } while ($row_record1 = mysql_fetch_assoc($record1));?></textarea>

phranque

3:26 pm on Nov 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the following will work to skip any rows where one or more of the 3 email addresses is NULL:
SELECT DISTINCT email, email2, email3 FROM customers LEFT JOIN email_cust ON email_cust.email_ID = customers.customer_ID LEFT JOIN state_cust ON state_cust.state_ID = customers.customer_ID WHERE state LIKE '%%%s%% AND email IS NOT NULL AND email2 IS NOT NULL AND email3 IS NOT NULL

otherwise you will have to independently echo each email value and put an "if" test on each echo.
not sure of php syntax, but something like:
...<?php if ($row_record1['email']){echo $row_record1['email']."\n"}?>...