Re: Change styling depending on var value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2009-11-20 at 14:45 -0500, Phil Matt wrote:

> I am trying to style HTML table cells depending on the values stored in 
> a MySQL db. Thanks to other on this list, I can now refer to the 
> variable that holds a CSS styling value.
> 
> Now, I need to apply different values of that variable, depending on the 
> content of the table cell itself.
> 
> I tried something like this, where $row[3] contains string values:
> 
> $entree ="meat";
> $dessert ="ice cream";
> $beverage="coffee";
> 
> (then the query that returns the data)
> 
> if ($row[3] = $entree)
> {
> $rowcolor = "color:red";
> elseif ($row[3] = $dessert)
> {
> $rowcolor = "color:blue";
> elseif ($row[3] = $beverage)
> {
> $rowcolor = "color:green";
> }
> else
> {
> $rowcolor ="color:black";
> }
> 
> I think I'm not properly expressing that I want the values in the 
> $row[3] compared to those in the specified vars
> 
> Thanks again.
> 


Well, you're main problem here is that you are only using a single =
character. What that is saying to PHP is: "if you let me assign the
value of $beverage to $row[3] then do this next bit", but what I think
you wanted it to say was "if $row[3] is the same as $beverage then do
this next bit", which would need == instead of =



Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux