Welcome to WebmasterWorld Guest from 54.146.221.231

Forum Moderators: not2easy

Message Too Old, No Replies

Show table grid even if no data in cell

     
3:15 pm on Dec 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 29, 2005
posts:3
votes: 0


Morning,

I am trying to create table from a database that needs to be printed out. What happens now is the data comes out fine but the table only shows the lines if there is data in the table. Is there a way to do this so all the grid lines show up regardless?

Thanks

Laura

3:37 pm on Dec 29, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:132
votes: 0


Have your script stick an   in any cells that are empty. If you are using php, it's

if(empty($foo)){
$foo = " ";
}

3:49 pm on Dec 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 29, 2005
posts:3
votes: 0


Like so?

mssql_data_seek ($result, 0);
while ($row = mssql_fetch_assoc ($result)) {
echo "<tr>\n";
foreach ($row as $column)
{
if(empty($column))
{
$column= "&nbsp;";
}
else
{
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
}

3:56 pm on Dec 29, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4965
votes: 10


Like so:

mssql_data_seek ($result, 0);
while ($row = mssql_fetch_assoc ($result)) {
echo "<tr>\n";
foreach ($row as $column)
{
if(empty($column))
{
$column= "&nbsp;";
}

echo "<TD>$column</TD>\n";

echo "</TR>\n";
}

4:08 pm on Dec 29, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:132
votes: 0


Fotiman is right - you want to echo it either way. All the if statement should to is set $column = "&nbsp" IF the variable $column is empty

In yours it would not echo a <TD> at all if $column is empty

4:25 pm on Dec 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 29, 2005
posts:3
votes: 0


Thanks so much! That works perfect. Thanks again for all the help.

Laura

5:34 pm on Dec 29, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 26, 2004
posts:1497
votes: 0


Ideally you should be able to do:

table { empty-cells: show; }

instead of adding an nbsp entity, but I've no idea what browser support is like.