Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Assigning a color depending on the value
Old 07-13-2010, 08:37 AM Assigning a color depending on the value-Resolved
Average Talker

Posts: 22
Trades: 0
I am trying to assign a font color red when the value is 'red', yellow when the value is 'yellow', green when the value is 'green' and blue when the value is 'on vacation'.

The color of the value is always red - it does not change color.


PHP Code:
<?php 
include("config.php"); 
$connection=mysql_connect($hostname,$user,$pass) or die ("Failed to connect."); 
mysql_select_db($dbname,$connection) or die ("Cannot connect to DB"); 
 
 
$result=mysql_query("SELECT * FROM rlgl_std WHERE id='$id'") or die ("Could not execute query."); 
 
$id=$_GET['id']; 
 
while(
$rows=mysql_fetch_array($result)){ 
?> 
<html> 
<head> 
</head> 
 
<body> 
<?php 
$availability
=$_GET['availability']; 
if ( 
$availability='Red' ) { 
    echo 
"<p style=\"color:#ff0000\">$rows[availability]</p>"

elseif ( 
$availability='Yellow' ) { 
    echo 
"<p style=\"color:#ffcc00\">$rows[availability]</p>"

elseif ( 
$availability='Green' ) { 
    echo 
"<p style=\"color:#009900\">$rows[availability]</p>"

elseif ( 
$availability='On Vacation' ) { 
    echo 
"<p style=\"color:#000066\">$rows[availability]</p>"


?> 
</body> 
</html>

Last edited by beylah; 07-13-2010 at 10:26 AM..
beylah is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-13-2010, 08:54 AM Re: Assigning a color depending on the value
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You are using the assignment operator = instead of the comparison operator ==.

The behavior you described is occurring because, in PHP, assignments return the value being assigned. In an if statement, anything that isn't false, 0, the empty string, or null is considered false. Everything else is true, hence $availability='Red' evaluates to true.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-13-2010, 09:11 AM Re: Assigning a color depending on the value
Average Talker

Posts: 22
Trades: 0
when i use the == i get no result

i have tried this and get no results either

if ( $availability=='Red' ) {
echo '<p style="color:#ff0000;text-align:center;font-family:Helvetica,sans-serif;font-size:12px;font-weight:bold">'.$rows['availability'].'</p>';
}

Last edited by beylah; 07-13-2010 at 09:17 AM..
beylah is offline
Reply With Quote
View Public Profile
 
Old 07-13-2010, 10:21 AM Re: Assigning a color depending on the value
Average Talker

Posts: 22
Trades: 0
i have resolved it - i instead of using
PHP Code:
$availability=$_GET['availability']; 
i have used
PHP Code:
$availability=$rows['availability']; 
PHP Code:
$availability=$rows['availability']; 
if ( 
$availability=="Red" 
{ echo 
"<p style=\"color:#ff0000\">Red</p>"; } 
if ( 
$availability=="Yellow" 
{ echo 
"<p style=\"color:#ffcc00\">Yellow</p>"; } 
if ( 
$availability=="Green" 
{ echo 
"<p style=\"color:#009900\">Green</p>"; } 
if ( 
$availability=='On Vacation' 
{ echo 
"<p style=\"color:#000066\">On Vacation</p>"; } 
beylah is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Assigning a color depending on the value
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13256 seconds with 12 queries