ananaz Posted December 24, 2010 Share Posted December 24, 2010 Hello I want to be able to change the class depending on if a variable is 1 or 0. <html> <p class="note-general"> This is the general </p> <p class="note-warning"> And this is the warning </p> </html> I want the variable $adult (that can be 1 or 0) to set if the class should be a note-general or note-warning. Thank you for support Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted December 24, 2010 Share Posted December 24, 2010 <html> <?php if ($adult==0) { $class="note-general"; echo "<p class='$class'> This is the general </p>"; } if ($adult==1) { $class="note-warning"; echo "<p class='$class'> And this is the warning </p>"; } ?> </html> Quote Link to comment Share on other sites More sharing options...
the182guy Posted December 24, 2010 Share Posted December 24, 2010 $adult = 1; // add code to set the $adult variable $className = $adult == 1 ? 'note-general' : 'note-warning'; <html> ... <p class="<?php echo $className; ?>">some message</p> </html> Quote Link to comment Share on other sites More sharing options...
ananaz Posted December 24, 2010 Author Share Posted December 24, 2010 will this do? <p class="<?php if ($aresult1['adult']==0) { $class="note-general"; } else { $class="note-warning"; } echo "$class"; ?>"> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 24, 2010 Share Posted December 24, 2010 unless you'll be using $class later, there is no need to define it. <?php if ($adult==0) { echo "<p class='note-general'> This is the general </p>"; } else if ($adult==1) { echo "<p class='note-warning'> And this is the warning </p>"; } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 24, 2010 Share Posted December 24, 2010 but if you want to keep $class for later in the script: <?php if ($adult==0) { $class = 'note-general'; echo "<p class='$class'> This is the general </p>"; } else if ($adult==1) { $class = 'note-warning'; echo "<p class='$class'> And this is the warning </p>"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.