Jump to content

Table Formatting


jt2006

Recommended Posts

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>

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

[!--quoteo(post=387001:date=Jun 22 2006, 05:22 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Jun 22 2006, 05:22 PM) [snapback]387001[/snapback][/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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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;
Link to comment
Share on other sites


My example with the red xxx if varable not there.
[code]
<?
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>

<?}?>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.