0

I will change the background color of some table th. In my example here I used a <div>. I have a script, which seperate 2 different printing outputs in a css tab design, so it is the same website, if you change the tabs.

I want to use for every tab different backround-colors.

I have tried to add a new php variable into one class in my print.php file like `

<class="tab_new '.$css_class.'">

which should only have a css rule only for the backround color.

$css_class = 'classname1' // first case
$css_class = 'classname2' // second case

I will get the error PHP var $css_class is undefinied. But the problem is, that my print.php is requiering_once before the file, where the definition of $css_class is (verb.php).

Please have a look at this 2 files. Maybe my example here isn't correct for my question, but I don't know, how to explain it otherwise.

.blue  {background-color:CornflowerBlue; font-weight:bold}
<div class="blue">My backround is CornflowerBlue</div>
<br><br>
<div class="blue">My backround  should be green</div>

3
  • I don't see $css_class in print.php anywhere, but it looks like your problem is your functions. It looks like you are trying to reference a variable in global space from inside your function. Try adding global $css_class; to the top of the function. php.net/manual/en/language.variables.scope.php Commented Apr 5, 2016 at 21:38
  • @bassxzero Thanks for your comment. I don't add the css_class to the github version, because it wouldn't worked anyway. I have tried to use global $css_class and it worked. I have updated the files on github. Is this the best solution? Commented Apr 5, 2016 at 21:59
  • I made my comment an answer. Commented Apr 5, 2016 at 22:04

1 Answer 1

2

I don't see $css_class in print.php anywhere, but it looks like your problem is your functions. It looks like you are trying to reference a variable in global space from inside your function. Try adding global $css_class; to the top of the function. php.net/manual/en/language.variables.scope.php

Is this the best solution? IMO no. Google dependency injection and you will learn why it's not the best solution.

Is this the simplest solution? Judging based on the little bit of your code I can see, then I would say probably yes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.