I wish to suppress empty fields in the resulting array of a query against multiple address type tables. I'm getting:
Able, Ned
,
,
410.123.4577
Jones, Ed
123 4th Ave, Suite 1
Anytown, NY 12345
UNITED STATES OF AMERICA
212.111.9999
Smith, Vern
13 Rouge Ave
Toronto, ON M8U7X1
CANADA
604.949.9134
What I'd like is this:
Able, Ned
410.123.4577
Jones, Ed
123 4th Ave, Suite 1
Anytown, NY 12345
212.111.9999
Smith, Vern
13 Rouge Ave
Toronto, ON M8U7X1
CANADA
604.949.9134
Notice in the above that Ned Able has no address, so his address rows are suppressed, and Ed Jones has no country as the United States has been suppressed, whereas Vern Smith lives in Canada and his country is displayed.
I thought I'd use the logic of if address is not null then printf([address] and if country is not 'USA' then printf([country]) but I keep getting parse errors when I insert the if conditional.
Code is below. Where might I use some if logic, and what is the syntax, to suppress data? I attempted to put the if in the body of the while loop in order to check the values on each iteration, but again, I got a parse error.
Help?
$db = mysql_connect("localhost", "USERNAME", "pwd");
mysql_select_db("DATABASE",$db);
$result = mysql_query("SELECT A.LAST_NAME, A.FIRST_NAME, A.MID_NAME, B.ADDRESS_1, B.ADDRESS_2, B.ADDRESS_3, B.CITY, B.STATE, B.POSTAL, B.COUNTRY, C.PHONE, D.EMAIL, E.PL_YEAR, E.PL_SEM
FROM NAMES_TBL A
LEFT JOIN ADDRESS_TBL B ON (A.DBID = B.DBID AND B.EFF_DT <= CURRENT_DATE AND B.PREFERRED = 'Y')
LEFT JOIN PHONE_TBL C ON (A.DBID = C.DBID AND C.EFF_DT <= CURRENT_DATE AND C.PREFERRED = 'Y')
LEFT JOIN EMAIL_TBL D ON (A.DBID = D.DBID AND D.EFF_DT <= CURRENT_DATE AND D.PREFERRED = 'Y')
LEFT JOIN PLEDGED_TBL E ON A.DBID = E.DBID
WHERE A.EFF_DT <= CURRENT_DATE
ORDER BY A.LAST_NAME,A.FIRST_NAME",$db);
while ($row = mysql_fetch_array ($result)) {
printf("<p><b>%s, ",$row["LAST_NAME"]);
printf("%s ", $row["FIRST_NAME"]);
printf("%s</b><br>", $row["MID_NAME"]);
printf("%s ", $row["ADDRESS_1"]);
printf("%s ", $row["ADDRESS_2"]);
printf("%s<br>\n", $row["ADDRESS_3"]);
printf("%s, ", $row["CITY"]);
printf("%s ", $row["STATE"]);
printf("%s<br>\n",$row["POSTAL"]);
printf("%s<br>\n",$row["COUNTRY"]);
printf("%s",$row["PHONE"]);
printf("<br>\n%s",$row["EMAIL"]);
printf("<br>\nPledged: %s", $row["PL_SEM"]);
printf(" %s", $row["PL_YEAR"]);
}