Jump to content


Photo

Table Formatting


  • Please log in to reply
7 replies to this topic

#1 jt2006

jt2006
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 June 2006 - 09:58 PM

Hey all. Thanks for taking a look at this for me.

I have a form on my site to store peoples names, addresses and so on. I only require that a few of the fileds be entered. Things like phone number or state and zip are optional.

My problem is that when I display this information using the following format, any field that doesn't have a value also doesn't get my table formatting so I end up with a nice table border for first name and last name but I get a blank border for fields with no value. Here's my code and also a snippit of what my table looks like.

Thanks,
JT


echo "<table border='1'>";
echo "<tr> <th>First Name</th> <th>Last Name</th> <th>Maiden Name</th> <th>Spouse</th> <th>Address</th><th>City</th><th>State</th><th>Zip</th><th>Phone</th><th>Email</th></tr>";
while($row = mysql_fetch_array($result)) { // Print out the contents of each row into a table
echo "<tr><td>";
echo $row[fname];
echo "</td><td>";
echo $row[lname];
echo "</td><td>";
echo $row[maiden];
echo "</td><td>";
echo $row[spouse];
echo "</td><td>";
echo $row[address];
echo "</td><td>";
echo $row[city];
echo "</td><td>";
echo $row[state];
echo "</td><td>";
echo $row[zip];
echo "</td><td>";
echo $row[phone];
echo "</td><td>";
echo $row[email];
echo "</td></tr>";
}
echo "</table>";
echo "<br />";

?>


Results:

<br />
<table border='1'><tr> <th>First Name</th> <th>Last Name</th> <th>Maiden
Name</th> <th>Spouse</th> <th>Address</th><th>City</th><th>State</th><th>Zip</th><th>Phone</th><th>Email</th></tr>
<tr><td>firstname</td><td>lastname</td><td></td><td>spouse</td><td>address</td><td>city</td><td>state</td><td>zip</td><td

></td><td>email</td></tr>

</table>



#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 22 June 2006 - 10:22 PM

I presume you mean certain cells are 'collapsing' when there is no value, if that is the case, you could use an if statment for each cell ie if there is content/value then display it; if there is NO content/value display a non-breaking space or a transparent gif ( 1px high x whatever wide).

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 jt2006

jt2006
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 June 2006 - 07:42 PM

[!--quoteo(post=387001:date=Jun 22 2006, 05:22 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Jun 22 2006, 05:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I presume you mean certain cells are 'collapsing' when there is no value, if that is the case, you could use an if statment for each cell ie if there is content/value then display it; if there is NO content/value display a non-breaking space or a transparent gif ( 1px high x whatever wide).

Lite...
[/quote]

Not quite. The cell is there but there's no border lines seperating the cells. If you cut the generated HTML code, paste it in notepad and save it as .html then bring it up in a browser you'd see what I mean. Your If statement might work but I'm hoping there's another cleaner way.

thanks for the reply,
JT

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 26 June 2006 - 08:08 PM

If the table cell is empty (like <td></td>) It won't have any borders or background. You'll need to have at least a space (like <td> </td> or <td>& n b s p;</td> without the spaces).

NoGray.com


#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 09:32 PM

To set a table to show without any data in it your have to set the SIZE and WIDTH of the table size ok.
<?
database connection

database query

?>

<table border='1' WIDTH="" HEIGHT="">

<?

while($record=mysql_fetch_assoc($result)) {

?>

<td>Name:<?echo $record['name']?></td>
<td>Password:<?echo $record['password']?></td>

</table>

<?}?>

Good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 June 2006 - 10:14 PM

litebearer is right. nogray is right. If you have no content then what you see is the way browsers work. An empty cell is really empty! A really simple fix to the code you have is to change each <td> to <td>&nbsp;
Legend has it that reading the manual never killed anyone.
My site

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 10:36 PM


My example with the red xxx if varable not there.
<?
database connection

database query

?>

<table border='1'  bordercolor="black" WIDTH="" HEIGHT="">

<? 

while($record=mysql_fetch_assoc($result)) {

?>

<td>Name:<?

if(!$record['name']){

echo $record['name'];

}else{

echo  "<font color='red'>xxx</font>";

}

?></td>


<td>Password:<?

if(!$record['password']) {

echo $record['password'];

}else{

echo "<font color='red'>xxx</font>"
}
?></td>

</table>

<?}?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 jt2006

jt2006
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 June 2006 - 05:24 PM

Thanks everyone. This helps a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users