Weird variable behavior

I use a css sheet that’s actually .php so I can make cascading changes easily (style.php) e.g.
[php]a {color: <?php echo $AccentColor1 ?>;}[/php]

The colours are set in a separate file with an include command (colours.php). They’re typically directly assigned, e.g.
[php]$AccentColour2 = “#efefef”[/php]

One colour (and possibly more once I get this to work) is stored in a database and retrieved by $Main_colour. When I echo $Main_colour it shows the expected value, (in this case #a9100c).

Here’s where the problem arises…

If I put
[php]$AccentColour1 = “#a9100c”;[/php]
in colours.php, the css in style.php works and everything that is meant to be that colour IS that colour.

However, if I put
[php]$AccentColour1 = $Main_colour;[/php]
in colours.php, even though the main_colour variable displays the expected value when echoed, the css breaks and everything that is meant to be that colour comes out link blue.

It gets even more strange. If I put
[php]$TempVar = #cdcd57;
$AccentColor1 = $TempVar;
$AccentColor1 = $Main_colour;[/php]
the css works but everything that’s meant to be #a9100c comes out as #cdcd57 instead… EVEN THOUGH both $AccentColor1 and $Main_colour echo as #a9100c before and after the css is processed.

Why is the css refusing to accept $AccentColor1 = $Main_colour?

Post your code.

I did. There are no other lines referencing these variables.

Something is obviously overriding it, but without the actual code and not a couple of lines it’s going to be hard for us to help.

I don’t see why you’re doing it this way anyway… for consistency, your stylesheet once completed should never need changing until you come to do a re-design.

I’m doing it this way so the same theme can be used for other sites with colour changes made via admin backend rather than going into the code. Not all users are comfortable with code.

If there were something overriding it and changing the value of $AccentColor1, wouldn’t $Accentcolor1 echo the new value? The css uses only [php]a {color: <?php echo $AccentColor1 ?>;}[/php] so I can’t imagine it’s being overridden there.

it looks to me like the problem could be caused by the hash # being used as a comment rather than the beginning of a colour reference:

[php]

this is a comment, so is the next line…

#a9100c[/php]

Let me know how you get on.
Red :wink:

And that my friend, is exactly why i use a very similar system. :wink:

I suspected that as well. But if I change the defining bit and say

[php]if (!isset($Bond_main_colour)) { $AccentColor1 = “#cdcd57”; }

if (isset($Bond_main_colour)) { $AccentColor1 = “#a9100c”; }[/php]

then $AccentColor1 echoes as #a9100c on screen before and after the css line is processed, but the css thinks it’s #cdcd57.

excuse the change in variable name from $Main… to $Bond… it’s a work in progress. in the code it’s consistent before testing.

why are you doing the same check twice?
this is easier, $Bond_main_colour is either set or it’s not…

[php]if(isset($Bond_main_colour)) {
$AccentColor1 = ‘#a9100c’;
}
else {
$AccentColor1 = ‘#cdcd57’;
}[/php]

This is a snippet taken from my actual CSS of one of the sites.

[php]<?php
if(isset($style[‘bgcolour’])) {
?>
#page {
background-color:<?php echo $style['bgcolour']; ?>;
}
<?php

}
?>
[/php]

As you can see, the info is pulled from the database and assigned at runtime.

Because when I did it the other way it was always defaulting to the last hex value listed. Running a not if / if check made it do both. It got me no farther ahead but at least showed that $bond_main_colour was doing something.

I’ve tried that too. Even though every other option successfully pulls from the dBase without a problem for text, numbers, etc. elsewhere on the site, it’s just this bloody colour giving me grief.

I’ve confirmed the STRLEN is only 7 characters. I’ve looked at it in the MySQL database and I’ve seen it is, in fact, #a9100c. I’ve echoed $Bond_main_colour to screen and there it is, #a9100c.

Yet [php]a {color: <?php echo $Bond_main_colour ?>;}[/php] still breaks the css.

can you post me the code from the very first time $Bond_main_colour is written upto this point:
[php]a {color: <?php echo $Bond_main_colour ?>;}[/php]

Red :wink:

[php]<?php header("Content-type: text/css"); ?>

<?php include ('includes/default_settings.php') ?>

/*********************************************

  1. CSS Reset ------------------------- All Theme Files
  2. Header ---------------------------- header.php
  3. Navigation ------------------------ header.php
  4. Featured Scroller ----------------- Bond_featured_posts.php
  5. Homepage --------------------------- index.php
  6. Posts & Pages ---------------------- page.php, single.php
  7. Comments -------------------------- comments.php
  8. Sidebar & Widgets ------------------ sidebar.php
  9. Footer ---------------------------- footer.php
  10. Toolbox CSS ----------------------- All Theme Files

*********************************************/

/*********************************************

  1. CSS Reset ------------------------- All Theme Files

*********************************************/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; }

body { line-height: 1; height: 100%;}
ol, ul { list-style: none; }
blockquote, q { quotes: none; }

html, body {height:100%;}
ul {list-style: none;}
img, fieldset {border: 0;}
em {font-style: italic;}
strong {font-weight: bold;}

a {text-decoration:none; color: <?php echo $AccentColor1 ?>; outline:none; border:none;}[/php]

not quite what i asked for…

Where is $Bond_main_colour ??
Where is $AccentColor1 set??

I’m assuming the code i need to see is in this file: includes/default_settings.php (or possible one of the css files 0 / 9)

I don’t need to see private stuff like database details etc. so make sure anything like that is xxxxx out of the script and please post that one.

Ta.
Red :wink:

Whups!

$Bond_main_colour is stored as an option in the dBase. There is a call in the header that retrieves these options

[php]global $options;
foreach ($options as $value) {
if (get_settings( $value[‘id’] ) === FALSE) { $$value[‘id’] = $value[‘std’]; } else { $$value[‘id’] = get_settings( $value[‘id’] ); }
}[/php]

…and $Bond_main_option, if echoed from header or from default_settings displays the expected value so it is being pulled from the dBase.

default_settings.php:

[php]/********************************************************

	Default settings to get the theme started

********************************************************/

$mainWidth = “980”; // site body width
$ContentWidth = “700px”;

$slideWidth = “980”; // Slideshow width
$slideHeight = “325”; // Slideshow height

$AccentColor1 = “$Bond_main_colour”;

$AccentColor2 = “#cdcdcd”; // light grey

$AccentColor3 = “#ffffff”; // white

$AccentColor4 = “#2d2d2d”; // slate

$AccentColor5 = “#2e2e2e”; // grey

$AccentColor6 = “#828282”; // text grey

$AccentColor7 = “#333333”; // dark grey

$AccentColor8 = “#000000”; // black

$AccentColor9 = “#efefef”; // pale grey

// provides a blurred black outline around light text for better visibility against light backgrounds
$textShadow = “1px -1px 5px rgba(0, 0, 0, 0.2), -1px 1px 5px rgba(0, 0, 0, 0.2), 1px 1px 5px rgba(0, 0, 0, 0.2), -1px -1px 5px rgba(0, 0, 0, 0.2), 0px 1px 5px rgba(0, 0, 0, 0.2), 0px -1px 5px rgba(0, 0, 0, 0.2), 1px 0px 5px rgba(0, 0, 0, 0.2), -1px 0px 5px rgba(0, 0, 0, 0.2)”;

$textShadowIE = “filter: progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc) progid:DXImageTransform.Microsoft.DropShadow(rgba(0, 0, 0, 0.2), OffX=2, OffY=2) progid:DXImageTransform.Microsoft.Glow(Strength=5, rgba(0, 0, 0, 0.2)); -ms-filter: 'progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc) progid:DXImageTransform.Microsoft.DropShadow(rgba(0, 0, 0, 0.2), OffX=2, OffY=2) progid:DXImageTransform.Microsoft.Glow(Strength=5, rgba(0, 0, 0, 0.2))”;

[/php]

So which is it because these two variables are not the same?
In this short conversation you have changed variable names several times, not a good idea and are you sure you haven’t missed one as i see
CamelCase
humpCase
variables_with_underscores

You should stick with one type.
From other languages using variable names that begin with a capitol letter is usually a sign that it’s a class name
class Myclass
using variables with an underscore usually indicates a private function
_afunction()

for normal variables i suggest you use either $capitolSecond or $word_underscore_word types.

So, please check ALL your variables and report back.
Cheers,
Red :wink:

$Bond_main_option was a typo here. I was thinking of how options were pulled as I types the description to you.

The variable names change because I’m working on this actively and trying different things; changing the name ensures the error demonstrated is present, not in the cache. The variable name is only in 2 places; the admin file where the variable is captured in the backend, and in default_settings.php. And yes, they match.

reading through your code i don’t see why it shouldn’t work as you expect it to.
From here you’re going to have to start debugging to narrow it down to why?

I suggest using an echo command in your script starting immediately after the database call then move it a couple of lines and check the value is the same, then move it again until eventually you see a new value. You then have a starting point an end point and should be able to narrow it down until you pinpoint the exact line.

Let me know how you get on.
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service