Jump to content

help needed with changing td background with css and php


spindriftmed

Recommended Posts

hi guys,

 

the main layout of my websites is in a file called main.php. the main layout is constructed of a table and one of the cells has a background image which i would like to change to a specific image depending on which page is loaded.

 

PHP Code (main.php):

<?

$strClassType = "defaultPage";

if(isset($_GET["page"]))

{

$intPageType = $_GET["page"];

switch($intPageType)

{

case "Home": {$strClassType = "home";} break;

case "Portfolio": {$strClassType = "portfolioPage";} break;

default: {$strClassType = "defaultPage";} break;

}

}

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="style.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="javascript.js"></script>

<title>Visual Identity</title>

</head>

<body onload="MM_preloadImages('images/main/nav_over_01.gif','images/main/nav_over_03.gif','images/main/nav_over_04.gif','images/main/nav_over_05.gif','images/main/nav_over_06.gif')">

<table height="430" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td width="204" height="152" align="right" valign="bottom" background="images/main/panel_l.gif"><table border="0" cellpadding="0" cellspacing="0">

<tr>

<td><a href="main.php?pagename=home" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/main/nav_over_01.gif',1)"><img src="images/main/nav_01.gif" name="home" width="110" height="14" border="0" id="home" /><br />

</a><a href="main.php?pagename=portfolio" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('portfolio','','images/main/nav_over_02.gif',0)"><img src="images/main/nav_02.gif" name="portfolio" width="110" height="13" border="0" id="portfolio" /></a><a href="main.php?pagename=dyo" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('design','','images/main/nav_over_03.gif',1)"><br />

<img src="images/main/nav_03.gif" name="design" width="110" height="14" border="0" id="design" /><br />

</a><a href="main.php?pagename=decals" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('decals','','images/main/nav_over_04.gif',1)"><img src="images/main/nav_04.gif" name="decals" width="110" height="14" border="0" id="decals" /></a><br />

<a href="main.php?pagename=clients" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('clients','','images/main/nav_over_05.gif',1)"><img src="images/main/nav_05.gif" name="clients" width="110" height="14" border="0" id="clients" /></a><br />

<a href="main.php?pagename=contact" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','images/main/nav_over_06.gif',1)"><img src="images/main/nav_06.gif" name="contact" width="110" height="14" border="0" id="contact" /></a></td>

<td width="30"></td>

</tr>

<tr>

<td height="30"></td>

<td></td>

</tr>

</table></td>

<td width="10" valign="top"></td>

<td width="504" valign="bottom" class="<? echo $strClassType; ?>"><table width="504" height="365" border="0" cellpadding="0" cellspacing="0">

<tr>

<td width="20"></td>

<td width="464" valign="top"><?php @ require_once ("./$pagename.php"); ?>

</td>

<td width="20"></td>

</tr>

</table></td>

</tr>

</table>

<table width="718" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td align="right"><img src="images/main/copyright.gif" width="431" height="15" border="0" usemap="#MapMap" />

<map name="MapMap" id="MapMap">

<area shape="rect" coords="353,5,430,14" href="http://www.spindriftmedia.com" target="_blank" />

</map>

</td>

</tr>

</table>

</body>

</html>

 

 

...and this is what style.css looks like:

 

Code (style.css):

 

body{

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 10px;

color: #CCCCCC;

background-color: #666666;

margin-top: 62px;

scrollbar-3dlight-color: #666666;

scrollbar-arrow-color: #666666;

scrollbar-darkshadow-color: #666666;

scrollbar-face-color: #666666;

scrollbar-highlight-color: #666666;

scrollbar-shadow-color: #666666;

scrollbar-track-color: #666666;

}

a:link {

color: #CCCCCC;

text-decoration: none;

}

a:visited {

text-decoration: none;

color: #CCCCCC;

}

a:hover {

text-decoration: none;

color: #E4E4E4;

}

a:active {

text-decoration: none;

color: #CCCCCC;

}

.imageborder{

border:2px solid #CCCCCC;

width: 100px;

height: 79px;

}

.titles { color: #CCCCCC; font-weight: bold; font-size: 12px;}

 

.homePage

{

background-image: "images/main/home.gif";

// Other Stuff

}

 

.portfolioPage

{

background-image: "images/main/portfolio.gif";

// Other Stuff

}

 

 

.defaultPage

{

background-image: "images/main/panel_r.gif";

// Other Stuff

}

 

can anyone see why no image is appearing at all? ive tried messing around with the css by putting things like:

 

td.homePage and using background-image: url('images/main/home.gif'); but the background image just doesnt ever appear.

 

thank you for any help which would be much appreciated.

 

all the best,

 

mark

Link to comment
Share on other sites

hi there,

 

thank you so much for the reply, thats great.

 

now i can get an image to appear for the background but it is just the default everytime.

 

im assuming it is something to do with the logic at the top of main.php or maybe my button links which are main.php?pagename=home etc.

 

do you have any ideas by any chance?

 

thanks again for all your help, much appreciated.

 

all the best,

 

mark

Link to comment
Share on other sites

hi,

 

thanks again, the css looks like:

 

body{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #CCCCCC;
background-color: #666666;
margin-top: 62px;
scrollbar-3dlight-color: #666666;
scrollbar-arrow-color: #666666;
scrollbar-darkshadow-color: #666666;
scrollbar-face-color: #666666;
scrollbar-highlight-color: #666666;
scrollbar-shadow-color: #666666;
scrollbar-track-color: #666666;
}
a:link {
color: #CCCCCC;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #CCCCCC;
}
a:hover {
text-decoration: none;
color: #E4E4E4;
}
a:active {
text-decoration: none;
color: #CCCCCC;
}
.imageborder{
border:2px solid #CCCCCC;
width: 100px;
height: 79px;
}
.titles {	color: #CCCCCC;	font-weight: bold; font-size: 12px;}
.homePage{background-image: url(images/main/home.gif);}
.portfolioPage{background-image: url(images/main/portfolio.gif);}
.defaultPage{background-image: url(images/main/panel_r.gif);}

Link to comment
Share on other sites

hi there,

 

thank you so much for all the valuable info and your time.

 

below is my code for main.php. my links look like main.php?pagename=home but ive changed the 'page' in the logic to say 'pagename' and changed homePage to say home. still the default appears every time. am i just being plain stupid?

 

thank you again, i owe you one for this!

 

mark

 

Code:

 

[color=red]<?
$strClassType = "defaultPage";
if(isset($_GET["pagename"]))
{
$intPageType = $_GET["pagename"];
switch($intPageType)
{
case "Home": {$strClassType = "home";} break;
case "Portfolio": {$strClassType = "portfolio";} break;
default: {$strClassType = "defaultPage";} break;
}
}

?> [/color]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="javascript.js"></script>
<title>Untitled Document</title>
</head>
<body onload="MM_preloadImages('images/main/nav_over_01.gif','images/main/nav_over_03.gif','images/main/nav_over_04.gif','images/main/nav_over_05.gif','images/main/nav_over_06.gif')">
<table height="430" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="204" height="152" align="right" valign="bottom" background="images/main/panel_l.gif"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><a href="[color=red]main.php?pagename=home[/color]" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/main/nav_over_01.gif',1)"><img src="images/main/nav_01.gif" name="home" width="110" height="14" border="0" id="home" /><br />
        </a><a href="main.php?pagename=portfolio" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('portfolio','','images/main/nav_over_02.gif',0)"><img src="images/main/nav_02.gif" name="portfolio" width="110" height="13" border="0" id="portfolio" /></a><a href="main.php?pagename=dyo" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('design','','images/main/nav_over_03.gif',1)"><br />
          <img src="images/main/nav_03.gif" name="design" width="110" height="14" border="0" id="design" /><br />
        </a><a href="main.php?pagename=decals" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('decals','','images/main/nav_over_04.gif',1)"><img src="images/main/nav_04.gif" name="decals" width="110" height="14" border="0" id="decals" /></a><br />
          <a href="main.php?pagename=clients" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('clients','','images/main/nav_over_05.gif',1)"><img src="images/main/nav_05.gif" name="clients" width="110" height="14" border="0" id="clients" /></a><br />
          <a href="main.php?pagename=contact" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','images/main/nav_over_06.gif',1)"><img src="images/main/nav_06.gif" name="contact" width="110" height="14" border="0" id="contact" /></a></td>
        <td width="30"></td>
      </tr>
      <tr>
        <td height="30"></td>
        <td></td>
      </tr>
    </table></td>
    <td width="10" valign="top"></td>
    <td width="504" valign="bottom" class="[color=red]<? echo $strClassType; ?>[/color]"><table width="504" height="365" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="20"></td>
        <td width="464" valign="top"><?php @ require_once ("./{$pagename}.php"); ?>
          </td>
        <td width="20"></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="718" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="right"><img src="images/main/copyright.gif" width="431" height="15" border="0" usemap="#MapMap" />
      <map name="MapMap" id="MapMap">
        <area shape="rect" coords="353,5,430,14" href="http://www.home.com" target="_blank" />
      </map>
    </td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

Now you have changed your links to ?p=home. So now the php block at the top of your page will not work!

 

Stop changing your url variables and your code will work!

 

Try the following code at the top fo your script:

$strClassType = 'defaultPage';

if(isset($_GET['pagename']))
{
    $intPageType = strtolower($_GET['pagename']);

    switch($intPageType)
    {
        case "home":
            $strClassType = 'homePage';
        break;
        case "portfolio":
            $strClassType = 'portfolioPage';
        break;

        default:
            $strClassType = "defaultPage";
    }
}

Make sure your links are set to ?pagename=YOUR_PAGE_NAME

Link to comment
Share on other sites

mega!!!!!!!!!!

 

it now works 110% perfectly!

 

thank you so much for all your time and please do not hesitate to ask if i can help you with anything (taking into consideration that you probably wont want it after seeing how useless i am with it!). however, hopefully i can help you with something in the future.

 

thank you again, much appreciated.

 

all the best,

 

mark

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.