Click to See Complete Forum and Search --> : how to change css style using php ?


ev66
05-12-2005, 02:30 PM
please could you tell me how to change the css style using php in the following
part of the program

<td align="center" valign="middle" class="largeblue"><?php echo '<p>' . $ans1 . '<p>'; ?></td>
<td width="50" align="center" valign="middle"><?php

// do some stuff using largeblue style

//put right or wrong on screen for answer 1
if (($whatradio==1) and ($whatradio==$qans)){echo '<p>' . correct . '<p>';$cc++;};
if (($whatradio==1) and ($whatradio!==$qans)) {echo '<p>' . '<class="redwrong">' . wrong . '<p>';};
if (($whatradio!=='1') and ($qans==1)){echo '<p>' . rightanswer . '<p>';};


i try to echo the word wrong using my redwrong css style,but it still appears
in the largeblue style.

thanks if you can help.
evan

BeachSide
05-12-2005, 02:41 PM
Have you tried...


/*
Notice you should have the class in the <p> tag and you are saying that the words 'correct', 'wrong', and 'rightanswer' are constants

also if you have !== you are looking for an absolute match which can be tricky

I am just assuming you are trying to see if it is equal or not equal to your variable

And there is no need for the semicolon at the end of your if statements
*/

if (($whatradio=='1') and ($whatradio==$qans)){echo '<p>correct<p>';$cc++;}
if (($whatradio=='1') and ($whatradio!=$qans)) {echo '<p class="redwrong">wrong<p>';}
if (($whatradio!='1') and ($qans==1)){echo '<p>rightanswer<p>';}

ev66
05-12-2005, 02:56 PM
thanks for the help,but didnt change the style.
i think the problem is that in the
first instance the style applies to the td, and then i try to change the text stlye,and this
is over ridden by the original td style.

NogDog
05-12-2005, 03:05 PM
Eh, Beachside got his reply in just before mine. :) Anyway, you handle 3 of the 4 logically possible cases. What if $whatradio != 1 and $qans != 1 ? I'd probably do something like:

if($whatradio == 1)
{
if($qans == 1)
{
echo '<p>correct<p>';
$cc++;
}
else
{
echo '<p class="redwrong">wrong<p>';
}
else # $whatradio != 1
{
if($qans == 1)
{
echo '<p>rightanswer<p>';
}
else
{
# what do you do when $whatradio != 1 and $qans != 1 ???????
}
}

NogDog
05-12-2005, 03:06 PM
thanks for the help,but didnt change the style.
i think the problem is that in the
first instance the style applies to the td, and then i try to change the text stlye,and this
is over ridden by the original td style.
Can we see your <style> section or CSS page where class redwrong is defined?

BeachSide
05-12-2005, 04:16 PM
Heh NogDog I was just fixing his current code but you are absolutly correct... :p

Yes, if either of those solutions are not working we will need to see the style as that php code should work because you are applying the style directly to the <p> tag

ev66
05-13-2005, 02:31 PM
I've got it working now.Thanks for your help Beachside,NogDog,with the coding
and the messy syntax i use.
Ta.
ev