This is a discussion on Cell Colour Change!!! within the PHP Language forums, part of the PHP Programming Forums category; Hi I am trying to change the colour of a cell depending on what page the user is on.. I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi I am trying to change the colour of a cell depending on what page the
user is on.. I have View.php the is loaded into every page! This is what I was trying to do but I got no clue how it goes If page is "home" Then cell colour should be blue If page is "register" Then cell colour should be Red If page is "contact us" Then cell colour should be yellow If some one can help me at least make a basic php structure for this I would appriciate it! |
|
|||
|
"Keith Mullin" <keith.mullin@sympatico.ca> wrote in message news:fNCqb.22446$mB5.1016724@news20.bellglobal.com ... > Hi I am trying to change the colour of a cell depending on what page the > user is on.. > > I have View.php the is loaded into every page! > > This is what I was trying to do but I got no clue how it goes > > If page is "home" Then cell colour should be blue > If page is "register" Then cell colour should be Red > If page is "contact us" Then cell colour should be yellow > > If some one can help me at least make a basic php structure for this I would > appriciate it! > Pass a page var with each link and in the cells: if($page=="home") { //make the background this color } elseif($page=="register") { //make the background this color } else { //and so on } Or get a bit fancier and use something like $_SERVER['PHP_SELF']; to see what page you're on. Steve. |
|
|||
|
*** Keith Mullin wrote/escribió (Thu, 6 Nov 2003 20:45:18 -0800):
> If page is "home" Then cell colour should be blue > If page is "register" Then cell colour should be Red > If page is "contact us" Then cell colour should be yellow Do you mean something like...? <style> ..blue{ background-color: #89D3F8; } ..red{ background-color: #FEB7A5; } ..yellow{ background-color: #FFFFAA; } </style> <? switch($_SERVER['PHP_SELF']){ case 'home.php': $style='blue'; break; case 'register.php': $style='red'; break; case 'contact.php': $style='yellow'; break; } ?> <table><tr><td class="<?=$style">....... -- -- -- Álvaro G. Vicario - Burgos, Spain -- |
|
|||
|
Keith Mullin wrote:
> This is what I have but does not work: > > <tr <?php if($page!=="home") { print(bgcolor="#006699"); } > elseif($page!=="compose") { print(bgcolor="#66CC33"); } > elseif($page!=="registration") { > print(bgcolor="#FF0000"); }elseif($page!=="contact") { > print(bgcolor="#FFCC00") else ( print(bgcolor="#006699"); } ?>> if ($page !== "home") { whatever } means: if the contents of the variable named $page are (very) *different* to "home" then do whatever I think you want if ($page === "home") { whatever } which means: if $page is (very) *equal* to "home" then do whatever But ... the switch solution provided by another poster is your best bet. switch ($page) { case 'home': echo 'bgcolor="#006699"'; break; case 'compose': echo 'bgcolor="#66CC33"'; break; // ... default: echo 'bgcolor="006699"'; } did you notice the home and default colors are the same? get the "home" out of the construct to speed up your code a few milliseconds :) -- ..sig |
|
|||
|
This is what I have but does not work:
<tr <?php if($page!=="home") { print(bgcolor="#006699"); } elseif($page!=="compose") { print(bgcolor="#66CC33"); } elseif($page!=="registration") { print(bgcolor="#FF0000"); }elseif($page!=="contact") { print(bgcolor="#FFCC00") else ( print(bgcolor="#006699"); } ?>> <td height="14" colspan="5" valign="top"><!--DWLayoutEmptyCell--> </td> </tr> What happens is the View.php gets loaded into every page. I have a cell the I would like to change the colour depending on what page the user is on. but would like to leave the other cells alone. for example if($page!=="home") then the color (background color) of the cell should be #006699 if the page isnot "home" but its ($page!=="registration") the color of that cell should be #FF0000. would this require the use of a variable? I have no clue how to use them. Thanks "Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in message news:1mafccb0a87o8.qu1gi8t8br6a.dlg@40tude.net... > *** Keith Mullin wrote/escribió (Thu, 6 Nov 2003 20:45:18 -0800): > > If page is "home" Then cell colour should be blue > > If page is "register" Then cell colour should be Red > > If page is "contact us" Then cell colour should be yellow > > Do you mean something like...? > > <style> > .blue{ > background-color: #89D3F8; > } > .red{ > background-color: #FEB7A5; > } > .yellow{ > background-color: #FFFFAA; > } > </style> > <? > switch($_SERVER['PHP_SELF']){ > case 'home.php': > $style='blue'; > break; > case 'register.php': > $style='red'; > break; > case 'contact.php': > $style='yellow'; > break; > } > ?> > <table><tr><td class="<?=$style">....... > > > -- > -- > -- Álvaro G. Vicario - Burgos, Spain > -- |
|
|||
|
I my Gosh I got it to work... Thank you so mutch for explaning how its
done.. it was ! in $page== that I needed to take out........ Here is the working code for future ref' <tr bgcolor="# <?php if($page=="compose") { print("66CC33"); } elseif ($page=="registration") { print("FF0000"); } elseif($page=="contact") { print("FFCC00"); } else { print("006699"); } ?>"> <td height="14" colspan="5" valign="top"><!--DWLayoutEmptyCell--> </td> </tr> Thanks k.M "Pedro Graca" <hexkid@hotpop.com> wrote in message news:bohciq$1emo9i$1@ID-203069.news.uni-berlin.de... > Keith Mullin wrote: > > This is what I have but does not work: > > > > <tr <?php if($page!=="home") { print(bgcolor="#006699"); } > > elseif($page!=="compose") { print(bgcolor="#66CC33"); } > > elseif($page!=="registration") { > > print(bgcolor="#FF0000"); }elseif($page!=="contact") { > > print(bgcolor="#FFCC00") else ( print(bgcolor="#006699"); } ?>> > > if ($page !== "home") { whatever } > > means: > > if the contents of the variable named $page are (very) *different* to > "home" then do whatever > > > I think you want > > if ($page === "home") { whatever } > > which means: if $page is (very) *equal* to "home" then do whatever > > > > But ... the switch solution provided by another poster is your best bet. > > switch ($page) { > case 'home': echo 'bgcolor="#006699"'; break; > case 'compose': echo 'bgcolor="#66CC33"'; break; > // ... > default: echo 'bgcolor="006699"'; > } > > did you notice the home and default colors are the same? > get the "home" out of the construct to speed up your code a few > milliseconds :) > > -- > .sig |