jt2006 Posted June 22, 2006 Share Posted June 22, 2006 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,JTecho "<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 tableecho "<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> Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/ Share on other sites More sharing options...
litebearer Posted June 22, 2006 Share Posted June 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-48626 Share on other sites More sharing options...
jt2006 Posted June 26, 2006 Author Share Posted June 26, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-49781 Share on other sites More sharing options...
nogray Posted June 26, 2006 Share Posted June 26, 2006 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). Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-49792 Share on other sites More sharing options...
redarrow Posted June 26, 2006 Share Posted June 26, 2006 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 connectiondatabase 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. Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-49816 Share on other sites More sharing options...
AndyB Posted June 26, 2006 Share Posted June 26, 2006 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> Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-49831 Share on other sites More sharing options...
redarrow Posted June 26, 2006 Share Posted June 26, 2006 My example with the red xxx if varable not there. [code]<?database connectiondatabase 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] Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-49837 Share on other sites More sharing options...
jt2006 Posted June 27, 2006 Author Share Posted June 27, 2006 Thanks everyone. This helps a lot! Quote Link to comment https://forums.phpfreaks.com/topic/12678-table-formatting/#findComment-50151 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.