Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Tables - displaying border with NO Content 1

Status
Not open for further replies.

tshey

Technical User
Dec 28, 2005
78
AU
I want to display dynamic content on a page in a table, however when there is a field without data in it the border does not appear, how can I make all cells appear even those without data.
 
For the cells that contain no data place a non-breaking space
Code:
 
in the cell.
 
This is not really a php question, but let me give you a quick answer.

By default, cells in a table with no content do not have border around them. In CSS there is a property called [tt]empty-cells[/tt], which is meant to toggle between showing borders for such cells or not. So if you add [tt]empty-cells: show;[/tt] to your td declaration, it should work. IE however, will shoot you down as it does not support that. That is why it is more cross-browser compliant at the moment to simply put some content in the otherwise empty cell. In your PHP script check if the value is empty and if it is, replace it with  . That way the cell will have certain content and the borders will appear.
 
How do I write this script ? Check if value is empty - replace with  
 
How about a simple:
Code:
if (empty($val))
{
  $val = ' ';
}
 
thanks so much, I have been coding for 4 days straight day and night. My brain is numb!
 
I have a database table that is pulled into a members page.
some of the code is as follows. My question is where do I put the bit of coding stated in the previous post?
<tr>
<td class="blackhead1">Date Submitted</td>
<td class="blackhead1">Wedding Date</td>
<td class="blackhead1">Wedding Location</td>
<td class="blackhead1">Brides Fullname</td>
<td class="blackhead1">Grooms Fullname</td>
</tr>
<tr>
<td class="customers"><?php echo $row_rs_customers['sub_day']; ?>
/
<?php echo $row_rs_customers['sub_month']; ?>
/
<?php echo $row_rs_customers['sub_year']; ?>

</td>

<td class="customers"><?php echo $row_rs_customers['wed_day']; ?>
/
<?php echo $row_rs_customers['wed_month']; ?>
/
<?php echo $row_rs_customers['wed_year']; ?></td>


<td class="customers"><?php echo $row_rs_customers['wedding_location']; ?></td>

<td class="customers"><?php echo $row_rs_customers['brides_fullname']; ?></td>

<td class="customers"><?php echo $row_rs_customers['grooms_fullname']; ?></td>
 
You can always do it this way:

Code:
<td class="customers">[red]&nbsp;[/red]<?php echo $row_rs_customers['sub_day']; ?>
 / 
<?php  echo $row_rs_customers['sub_month']; ?>
 / 
<?php echo $row_rs_customers['sub_year']; ?>

[red]&nbsp;[/red]</td>

Lee
 
Thankyou very much, I tried that initially, but only inserted the &nbsp; once. Can I ask what might seem a very stupid question! Why do you put &nbsp; twice?
 
I'd guess trollacious suggested it to balance your display. typically date are centered in tabular display and without a non-breaking space either side, it would not have looked right. the borders would have (should have) displayed in any scenario, even without the nbsps bacause the slashes are not echoed conditionally (ie if the date is blank the slashes will still display). perhaps this is not an issue for you as you validate the dates before inserting them into the db?

sorry to suggest yet another method to you, but you might consider the following as a generic method. what the code does is first go through the current row and test whether any of the items are empty or null and if they are, transform them into a non-breaking space. then the code extracts the array into its own variables making them easier to handle inside your table (or a form). a tip is to keep your db column names the same as your form element names.

one other tip - don't separate your dates into day month year etc. either store them as a mysql date (not my preference but makes it easier to read the table natively) or store it as a unix timestamp in an integer field. with the latter dates become consistently easy to handle and perform maths on.

Code:
<table>
<tr>
<td class="blackhead1">Date Submitted</td>
<td class="blackhead1">Wedding Date</td>
<td class="blackhead1">Wedding Location</td>
<td class="blackhead1">Brides Fullname</td>
<td class="blackhead1">Grooms Fullname</td>
</tr>
<?
//connect to db and select database
$query = ""; //insert query
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc($result)):
	foreach ($row as &$val):
		$val = empty($val) ? "&nbsp;" : $val;
	endforeach;
	extract ($row); 
	$date_submitted = date ("j/n/Y", strtotime("$sub-year-$sub_month-$sub_day"));
	$wedding_date = date ("j/n/Y", strtotime("$wed_year-$wed_month-$wed_day"));
?>
<tr>
<td class="customers"><?=$date_submitted?></td>
<td class="customers"><?=$weddingdate?></td>
<td class="customers"><?=$wedding_location?></td>
<td class="customers"><?=brides_fullname?></td>
<td class="customers"><?=$grooms_fullname?></td>
</tr>
<? endwhile; ?>
</table>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top