Current location: Hot Scripts Forums » Programming Languages » PHP » show empty fields


show empty fields

Reply
  #1 (permalink)  
Old 04-02-05, 12:24 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
show empty cells

I have a mysql query that calls a table to display, but the borders don't want to show around empty fields. How do I implement the "empty-cells: show" function into this script?

Thanks ahead!

PHP Code:



// Connect to Database and execute query ---------

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@
mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery "SELECT * FROM $table ORDER BY L_name";

$result mysql_query($sqlquery);


echo 
"<table border = 1 empty-cells:show>
<tr>
<td nowrap>First Name</td>
<td nowrap>Middle Name</td>
<td nowrap>Last Name</td>
<td nowrap>Spouse's Name</td>
<td nowrap>Nickname</td>
<td nowrap>Address</td>
<td nowrap>City</td>
<td nowrap>State</td>
<td nowrap>Zip Code</td>
<td nowrap>Country</td>
<td nowrap>Phone Number</td>
<td nowrap>Email Address</td>
<td nowrap>Years Rowed</td>
<td nowrap>Club Participation</td>
<td nowrap>Notes</td>
<td nowrap>Designation</td>
<td nowrap>Code</td>
</tr>"
;

while(
$row mysql_fetch_array($result)) {

echo 
"
<tr><td nowrap>"
.$row[F_name]."</td>
    <td nowrap>"
.$row[M_name]."</td>
    <td nowrap>"
.$row[L_name]."</td>
    <td nowrap>"
.$row[S_name]."</td>
    <td nowrap>"
.$row[N_name]."</td>
    <td nowrap>"
.$row[street]."</td>
    <td nowrap>"
.$row[city]."</td>
    <td nowrap>"
.$row[state]."</td>
    <td nowrap>"
.$row[zip]."</td>
    <td nowrap>"
.$row[country]."</td>
    <td nowrap>"
.$row[phone]."</td>
    <td nowrap>"
.$row[email]."</td>
    <td nowrap>"
.$row[years]."</td>
    <td nowrap>"
.$row[participation]."</td>
    <td nowrap>"
.$row[notes]."</td>
    <td nowrap>"
.$row[designation]."</td>
    <td nowrap>"
.$row[code]."</td>    
</tr>"
;

}

echo 
"</table>";

if(
mysql_num_rows($result)<1){
echo 
"<font face=Arial size=+0><b>No
Results!</b></font><br>"
;
}

mysql_free_result($result);
?> 

Last edited by creepycridler; 04-02-05 at 12:48 PM.
Reply With Quote
  #2 (permalink)  
Old 04-03-05, 01:24 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
add this foreach() inside the body of the while:
PHP Code:

foreach($row as $field => $value)

   if (empty(
$value))
       
$row[$field] = '&nbsp;'
so your while should be like this:
PHP Code:



while($row mysql_fetch_array($result)) {
   foreach(
$row as $field => $value)
      if (empty(
$value))
         
$row[$field] = '&nbsp;'//you can change the value from "space" to whatever you want 

  
echo "
<tr><td nowrap>"
.$row['F_name']."</td>
    <td nowrap>"
.$row['M_name']."</td>
    <td nowrap>"
.$row['L_name']."</td>
    <td nowrap>"
.$row['S_name']."</td>
    <td nowrap>"
.$row['N_name']."</td>
    <td nowrap>"
.$row['street']."</td>
    <td nowrap>"
.$row['city']."</td>
    <td nowrap>"
.$row['state']."</td>
    <td nowrap>"
.$row['zip']."</td>
    <td nowrap>"
.$row['country']."</td>
    <td nowrap>"
.$row['phone']."</td>
    <td nowrap>"
.$row['email']."</td>
    <td nowrap>"
.$row['years']."</td>
    <td nowrap>"
.$row['participation']."</td>
    <td nowrap>"
.$row['notes']."</td>
    <td nowrap>"
.$row['designation']."</td>
    <td nowrap>"
.$row['code']."</td>    
</tr>"
;


and note that I put quotes in all $row['FIELD'] because this the correct way to do it! other wise you were making php throw notices each time and also waste time looking for constants with the same names of the field..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 04-03-05 at 01:37 AM.
Reply With Quote
  #3 (permalink)  
Old 04-03-05, 06:04 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks dude. I appreciate your feedback!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add new fields to front page of CNCat? skimpydj PHP 0 01-21-05 12:07 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Help me guys Mister B. ASP 1 09-09-03 09:12 PM


All times are GMT -5. The time now is 05:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.