replace empty fields with  

admin

Administrator
Staff member
I'm generating a table from a MySQL query. I'd like to insert a   into each empty cell where no data was returned so the table formatting will look better. Can someone let me know the most efficient way to achieve this? Here is the piece of code I'm working on. Thanks.

//Define the Statement
$dbquery = "select * from " . $databaseName . ".card order by last, company";

// Execute the Statement
$result = mysql_db_query($databaseName,$dbquery)
or die("<br>Xeno Phone Book ERROR: Unable to make db query<br>\n");

// Display the results of the search

GenerateGenericHTMLHeader() ;

// count the records returned and display the results
printf("<font face=\"arial, helvetica, sans-serif\" size=\"2\"><b>Your search has returned " . mysql_num_rows ($result) . " results</b></font>");

printf("<TABLE BORDER=\"1\" width=\"2000\" cellpadding=\"2\" cellspacing=\"0\" BGCOLOR=\"#ffffff\" NOSAVE>\n");

printf("<TR>
<TD bgcolor=\"#aaccaa\"><B>&nbsp;</B></TD>
<TD bgcolor=\"#aaccaa\"><B>First</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Last</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Company</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Home</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Work</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Cel</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Page</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Fax</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Other</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Email</B></TD>
<TD bgcolor=\"#aaccaa\"><B>URL</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Address</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Address&nbsp;2</B></TD>
<TD bgcolor=\"#aaccaa\"><B>City</B></TD>
<TD bgcolor=\"#aaccaa\"><B>State</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Zip</B></TD>
<TD bgcolor=\"#aaccaa\"><B>Country</B></TD>
</TR>\n");

while (($row = mysql_fetch_object($result))){

printf("<TR><TD><A HREF=http://www.phpbuilder.com/board/archive/index.php/\"modify.php?recno=%s\"><I>Modify</I></A></TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
</TR>\n",
$row->recno, $row->first, $row->last, $row->company, $row->home, $row->work, $row->cel, $row->page, $row->fax, $row->other, $row->email, $row->url, $row->address, $row->address2, $row->city, $row->state, $row->zip, $row->country );
}

printf("</TABLE>\n");
 
Back
Top