I am working on an "e-commerce" project so to speak and I have a "problem" that I want to solve.
I have a product and its respective "STOCK" field. The admin enters the panel, adds a product and puts stock = yes.
The "Yes" and "No" are added by the admin (or modified). In this case, the Yes / No is stored in the DB as varchar(2).
And when entering the product page:
Print stock (Yes or No, depending on how it is placed in the Database).
What I want is that a class be added to that Yes or No.
yes = green
no = red
What I have thought is to add an "if".
if (strpos($columnas['stock'], 'Yes') !== false) {
(Agregar clase color green)
}
if (strpos($columnas['stock'], 'No') !== false) {
(Agregar clase color green)
}
Some answer?
EDIT: If the idea of the IF is correct, using strpos or strcmp, how could the green/red color change depending on whether the result is Yes or No?
You can use the strcmp function , note that this comparison is case sensitive. Yes returns
0
are the same. For the classes if you use youbootstrap
could call your classlabel
, otherwise you would definecss
the class in your and manually add thecolor: red
or property to itcolor:green
.You do want it to ignore case.