Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP within a table

Featured Replies

I've created a 3 column table as shown below. The middle column has a background image but when the php statement is included the background image vanishes. Do I have to use php to declare the background somehow?

 

<table style="width: 100%">
<tr>
	<td> </td>
	<td style="background-image: url('images/background.png')">			
		<? currentLink("index.php", "Home", "Left"); ?>		
	</td>
	<td> </td>
</tr>
</table>

If you are using this as your layout, you shouldn't be using a table.

 

If you are using it for data, if the 2 side columns are empty they should contain   in them to validate properly and to avoid any problems when displaying in the browser.

If you are using this as your layout, you shouldn't be using a table.

 

If you are using it for data, if the 2 side columns are empty they should contain   in them to validate properly and to avoid any problems when displaying in the browser.

 

Also its best not to use short tags

 

<? currentLink("index.php", "Home", "Left"); ?>

 

Use

 

<?php currentLink("index.php", "Home", "Left"); ?>

 

Pat

  • Author

Thanks for the pointers. I've included all relivant code here with the updates, table seems to have skewed, can be viewed at http://www.alco-owl.co.uk/index.php.

 

#linkbar {
	width:100%;
height: 29px;
padding: 0px;
}

#linkbarOuter {
height: 29px;
padding: 0px;
color: #000000;
font-weight: bold;
}

 

 

<div id="linkbar">
<center>
<table id="linkbarOuter" cellpadding="3" cellspacing="0">
	<tr>
	<td width="30%"><img src="../images/corner.png" width="17" height="29" alt="corner"></td>
	<td width="39%%" background="images/background.png">
		<?php currentLink("index.php", "Home", "Left"); ?>
		<?php currentLink("pricelist.php", "Price List","Middle"); ?>
		<?php currentLink("faq.php", "FAQ","Middle"); ?>
		<?php currentLink("tc.php", "T&C","Right"); ?>
	<td width="31%"><img src="../images/cornerright.png" width="17" height="29" alt="corner"></td>
	</tr>
</table>
<p></p>
<p></p>
</center>
</div>

<?php

function currentLink ($filename, $pagetitle,$location) {
//
//	This is a function to assign the correct rollover and background to the links
//	in the link bar. It either assigns the default background and rollover image
//	or a "highlighted" background if this is in the appropriate section.
//

// do specific actions for the homepage
if ( (substr($_SERVER["REQUEST_URI"], -4, 4) == "com/") && ($filename == "/index.php")) {
	echo '<td id="linkbarCellCurrent" class="linkbarCell' . $location . '"  onmouseover="tdmouseovercurrent(this)" onmouseout="tdmouseoutcurrent(this)">';
	echo '<a href="' . $filename . '">' . $pagetitle . '</a></td>';
	return;
}

// do standard options now
if (substr($_SERVER["REQUEST_URI"], -5, 5) == substr($filename, -5, 5)) {
	// if the requested page is the same as the current item, highlight it
	echo '<td id="linkbarCellCurrent" class="linkbarCell' . $location . '"  onmouseover="tdmouseovercurrent(this)" onmouseout="tdmouseoutcurrent(this)">';
	echo '<a href="' . $filename . '">' . $pagetitle . '</a></td>';
} else if ( ( (substr($_SERVER["REQUEST_URI"], -7, 7) == "red.php") || (substr($_SERVER["REQUEST_URI"], -7, 7) == "ile.php") || (substr($_SERVER["REQUEST_URI"], -7, 7) == "ler.php") ) && ($filename == "/products.php")) {
	// if the requested page is any of the products sub pages and the item is products, highlight it
	echo '<td id="linkbarCellCurrent" class="linkbarCell' . $location . '"  onmouseover="tdmouseovercurrent(this)" onmouseout="tdmouseoutcurrent(this)">';
	echo '<a href="' . $filename . '">' . $pagetitle . '</a></td>';
} else {
	// otherwise, display the normal non-highlighted options
	echo '<td class="linkbarCell' . $location . '"  onmouseover="tdmouseover(this)" onmouseout="tdmouseout(this)">' . "\n";
	echo '<a href="' . $filename . '">' . $pagetitle . '</a></td>' . "\n";
}
}

?>

It's due to the widths in the table. But there is no reason that you should be using tables. That design is easy enough to do using DIV's and CSS.

  • Author

How would I use a background image between the two corners without using a table?

How would I use a background image between the two corners without using a table?

Which background image?

 

There shouldn't be any tables on that page unless you are displaying tabular data.

  • Author
Which background image?

 

There shouldn't be any tables on that page unless you are displaying tabular data.

 

The table is 3 columns, first has a corner image, second has a background image, third has a corner image. The php is in the second column. I wasn't sure how to get that arrangement without a table.

 

	<table id="linkbarOuter" cellpadding="3" cellspacing="0">
	<tr>
	<td width="30%"><img src="../images/cornerleft.gif" width="18" height="29" alt="corner"></td>
	<td width="39%%" background="images/navbg.gif">
		<?php currentLink("index.php", "Home", "Left"); ?>
		<?php currentLink("pricelist.php", "Price List","Middle"); ?>
		<?php currentLink("faq.php", "FAQ","Middle"); ?>
		<?php currentLink("tc.php", "T&C","Right"); ?>
	<td width="31%"><img src="../images/cornerright.gif" width="18" height="29" alt="corner"></td>
	</tr>
</table>

The table is 3 columns, first has a corner image, second has a background image, third has a corner image. The php is in the second column. I wasn't sure how to get that arrangement without a table.

 

	<table id="linkbarOuter" cellpadding="3" cellspacing="0">
	<tr>
	<td width="30%"><img src="../images/cornerleft.gif" width="18" height="29" alt="corner"></td>
	<td width="39%%" background="images/navbg.gif">
		<?php currentLink("index.php", "Home", "Left"); ?>
		<?php currentLink("pricelist.php", "Price List","Middle"); ?>
		<?php currentLink("faq.php", "FAQ","Middle"); ?>
		<?php currentLink("tc.php", "T&C","Right"); ?>
	<td width="31%"><img src="../images/cornerright.gif" width="18" height="29" alt="corner"></td>
	</tr>
</table>

 

HTML:

<div class="whatever">
 <div class="left"></div>
 <div class="right"></div>
 <div class="content">
<?php currentLink("index.php", "Home", "Left"); ?>
<?php currentLink("pricelist.php", "Price List","Middle"); ?>
<?php currentLink("faq.php", "FAQ","Middle"); ?>
<?php currentLink("tc.php", "T&C","Right"); ?>
 </div>
</div>

 

CSS:

.whatever {
 width: 400px;
 height: 30px;
 overflow: hidden;
 }
.left {
 width: 30px;
 height: 30px;
 float: left;
 background: url('left.jpg') top left no-repeat;
 }
.right{
 width: 30px;
 height: 30px;
 float: right;
 background: url('right.jpg') top left no-repeat;
 }
.content span {
 width: 85px;
 display: block;
 float: left;
 line-height: 30px;
 padding: 0;
 margin: 0;
 text-align: center;
 }

 

Replacing span with whatever tag your php outputs.

  • Author

Please forgive my lack of understanding of this div setup. When I change the php from echo '<td id="linkbarCellCurrent" to echo '<div id="linkbarCellCurrent" the rest of the page fails to load.

Perhaps you PHP is looking for tables then, which is pretty poor.

  • Author

Apologies. It is all in post 5 of this thread. It's simply highlighting a tab if you're on that page and highlighting tabs on mouseovers.

Oh, I can't see a problem with that, unless it was coded badly.

  • Author

Seems to be all ok at the moment. One thing ive noticed though is that at the top of the page  characters are displayed. I've opened up the pages in notepad to check for any anomalous coding but cannot find where these characters are coming from :huh:

Looking at the source code you have some characters before the doctype:

 

<!doctype HTML PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

  • Author

Weird thing is it doesn't show them characters on the actual page on the server.

Weird thing is it doesn't show them characters on the actual page on the server.

 

Heres something interesting.

 

Yes, "" is the Byte Order Mark (BOM) of the Unicode Standard. Specifically it is the hex bytes EF BB BF, which form the UTF-8 representation of the BOM, misinterpreted as ISO 8859/1 text instead of UTF-8.

Probably what it means is that you are using a text editor that is saving files in UTF-8 with the BOM, when it should be saving without the BOM. It could be PHP files that have the BOM, in which case they'd appear as literal text on your page.

 

So I guess its a mixture of the way you are saving the file and the unicode standard on your page.

 

Pat

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.