Log in

View Full Version : Row Color Question



Titan85
01-28-2007, 06:28 AM
Ok, I am making a script for support tickets, and I want the cell that has the ticket status (low, medium, high, urgent) in it to show up a different color depending on its urgency. I am trying to do this by using the urgency column from the sql table. Here is how I am trying to do it:
// For each result found
while($row = mysql_fetch_array($result)) {
extract($row);

echo '
<tr>
<td>'.$id.'</td>
<td><a href="index.php?page=view&id='.$id.'">'.$subject.'</a></td>
<td style="background-color: '.$color.'">'.$urgency.'</td>
<td>'.$date.'</td>
<td><input type="checkbox" name="checkbox[]" value="'.$id.'" /></td>
<td>'.$status.'</td>
</tr>';

// Get status color
if($urgency == "low") {
$color == "#F19F00";
}
if($urgency == "medium") {
$color == "#EC7501";
}
if($urgency == "high") {
$color == "#EC3801";
}
if($urgency == "urgent") {
$color == "#FF0000";
}
}I am not sure if that way will work correctly or not, but as of now the color does not show up. I appreciate any help :)

mburt
01-28-2007, 12:51 PM
I'm assuming you haven't defined all of your variables for the rows, and that's probably why it won't work:

Make sure you define them:

id might be

$id = mysql_result($result,$i,"id");
and do that with the other undefined variables.
For that to work you must use an iterator in your while loop:


$i = 0;
while($row = mysql_fetch_array($result)) {
extract($row);

echo '
<tr>
<td>'.$id.'</td>
<td><a href="index.php?page=view&id='.$id.'">'.$subject.'</a></td>
<td style="background-color: '.$color.'">'.$urgency.'</td>
<td>'.$date.'</td>
<td><input type="checkbox" name="checkbox[]" value="'.$id.'" /></td>
<td>'.$status.'</td>
</tr>';

// Get status color
if($urgency == "low") {
$color == "#F19F00";
}
if($urgency == "medium") {
$color == "#EC7501";
}
if($urgency == "high") {
$color == "#EC3801";
}
if($urgency == "urgent") {
$color == "#FF0000";
}
i++;
}

thetestingsite
01-28-2007, 02:32 PM
Actually, if you just want to make the row color based upon what the urgency is, you don't need anything special other than the code snippet below:




while($row = mysql_fetch_array($result)) {
extract($row);


// Get status color
if($urgency == "low") {
$color == "#F19F00";
}
if($urgency == "medium") {
$color == "#EC7501";
}
if($urgency == "high") {
$color == "#EC3801";
}
if($urgency == "urgent") {
$color == "#FF0000";
}


echo '
<tr>
<td>'.$id.'</td>
<td><a href="index.php?page=view&id='.$id.'">'.$subject.'</a></td>
<td style="background-color: '.$color.'">'.$urgency.'</td>
<td>'.$date.'</td>
<td><input type="checkbox" name="checkbox[]" value="'.$id.'" /></td>
<td>'.$status.'</td>
</tr>';

}


Notice how I define the color variable before I display the information.

Hope this helps.

Titan85
01-28-2007, 02:46 PM
I tried both ways and both were unsuccessful. It just doesn't get the color value. Any ideas?

thetestingsite
01-28-2007, 02:49 PM
I just noticed (sorry, my daughter woke me up extremely early this morning) the following part



$color == "#F19F00";


should be


$color = "#F19F00";


Notice one equal sign ( = )

That should do it

Titan85
01-28-2007, 02:52 PM
The = sign was it! Thanks a ton. Howcome the double "=" was making it mess up?

thetestingsite
01-28-2007, 02:58 PM
When you use double equal signs, it means you are comaring something:



if ($urgency == "low")


That compares the value of urgency to something else ("low"). A single equal sign defines something:



$color = #000000;


Hope that helps.

mburt
01-28-2007, 04:51 PM
Ah yes, a common mistake to overlook the to operators.
== is a comparison operator
= is an assigning operator
=== assigns/compares the string/number based on the result

Titan85
01-28-2007, 09:15 PM
Thanks for the help, its working great :)