Jump to content

Change html class with php variable


ananaz

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/222577-change-html-class-with-php-variable/
Share on other sites

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>";
}
?>

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>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.