Jump to content

Need help displaying values in different color


bgbs

Recommended Posts

I'm trying to edit this script to change color for type_id

I set type_id values to WTS and WTB, and I need them to show different color.

Anyone know?

 

Here is the partial code from the file.

Your help appreciated.

 

 



<?php

echo "<tr><th>DEAL ID</th><th>Title</th><th>Severity</th><th>Priority</th><th>Type</th><th>Status</th><th>Submitter</th><th>Opened</th><th>Closed</th></tr>";

$record = OpenRecord("bug", "id,name,severity_id,priority_id,type_id,status_id,user_id,opendate,closedate", $keyword, "status_id num asc", "true"); // list all bugs
if (!$record) {
	echo "<tr><td colspan=\"12\">Empty</td></tr>";
}
else {
	$start_count = 0;
	$bug_count = 0;
	foreach ($record as $current_record) {
		if ($start_count >= $start && $bug_count < $bugs_per_page) {
			$value = explode($delimiter, $current_record);
			echo "<tr>";
			$colorclass = "";
			foreach ($value as $key => $cellval) {
				$cellval = $cellval;
				if ($key == 0) { 						
					$cellval = "<a href=\"index.php?page=bug_show&bug_id=".$cellval."\">".$cellval."</a>"; // the bug id is clickable
				}
				if ($value[8] == "Unconfirmed") { $colorclass = " class=\"blue\""; }
				elseif ($value[8] == "Under investigation" || $value[8] == "Confirmed") { $colorclass = " class=\"red\""; }
				else { $colorclass = " class=\"green\""; }
				if ($key == 9 && $cellval == "") { $cellval = "anonymous"; }
				echo "<td".$colorclass.">".$cellval."</td>";
			}
			echo "</tr>";
			$bug_count++;
		}
		$start_count++;
	}
}

?>

i dont have time to break down your code but for displaying things in different collors

css

.color1
{
color: red;
}
.color2
{color: blue;

 

php

<?php
foreach($color1 as $c)
{
  echo "<span class='color1'>$c</span><br />";
}


foreach($color2 as $c)
{
  echo "<span class='color2'>$c</span><br />";
}
?>

 

hopefully that helped. See ya!

Well, I've been working on it a little bit and here is what I came up with, but it is not displaying different colors despite what I've done to edit it. It just displays rows in white. What It should do is determine what value lies in a table cell and change the background color of the entire row. I think its not reading value[6] correctly.

 

			echo "<tr>";
			$colorclass = "";
			foreach ($value as $key => $cellval) {
				$cellval = $cellval;
				if ($key == 0) { 						
					$cellval = "<a href=\"index.php?page=bug_show&bug_id=".$cellval."\">".$cellval."</a>"; // the bug id is clickable
				}
				    if ($value[6] == "WTS") { $colorclass = " class='green' "; }
				elseif ($value[6] == "WTB") { $colorclass = " class='red' "; }
				elseif ($value[6] == "Other") { $colorclass = " class= 'blue'"; }
				if ($key == 9 && $cellval == "") { $cellval = "anonymous"; }
				echo "<td".$colorclass.">".$cellval."</td>";
			}

			echo "</tr>";

The type_id is $array[4] so change the 8 to 4 and swap out the values and change the colors if you want different colors and it should work without anything else needing to be changed.

 

How did you determine that? I tried what you said, and it doesnt work. The script uses values that get inputed using a drop down form.

value[6] is assigned to WTS,WTB and Other drop down values.  Those value are pulled from file database and spit into a table cell.

I dont know where the $array 4 comes in. 

 

        $value[0] = $_POST['bug_id'];

$value[1] = str_replace($delimiter, " ", stripslashes(htmlentities($_POST['name'])));

$value[3] = $_POST['priority_id'];

$value[6] = $_POST['type_id'];

$value[8] = $_POST['status_id'];

$value[9] = $_POST['user_id'];

 

nvm here is your problem

echo "<td".$colorclass.">".$cellval."</td>";

needs to be

echo "<td ".$colorclass." >".$cellval."</td>";

you need to have a space inbetween right now your tag is probably displaying as <tdclass=green> instead of <td class='green'>

 

you need to have a space inbetween right now your tag is probably displaying as <tdclass=green> instead of <td class='green'>

 

I placed the space the problem persists.

It disregards all the if and ifelse statements and only puts else.

 

                                        if ($value[6] == "WTS") { $colorclass = " class=\"green\""; }

elseif ($value[6] == "WTB") { $colorclass = " class=\"red\""; }

elseif ($value[6] == "Other") { $colorclass = " class=\"blue\""; }

else { $colorclass = " class=\"white\""; }

if ($key == 9 && $cellval == "") { $cellval = "anonymous"; }

echo "<td ".$colorclass.">".$cellval."</td>";

 

I got it from here.

$record = OpenRecord("bug", "id,name,severity_id,priority_id,type_id,status_id,user_id,opendate,closedate", $keyword, "status_id num asc", "true"); // list all bugs

I got it figured out, I needed to use $value[1] instead of [6]

 

I dont know why though.

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.