bgbs Posted February 9, 2010 Share Posted February 9, 2010 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++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/ Share on other sites More sharing options...
thewooleymammoth Posted February 9, 2010 Share Posted February 9, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009197 Share on other sites More sharing options...
bgbs Posted February 9, 2010 Author Share Posted February 9, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009202 Share on other sites More sharing options...
teamatomic Posted February 9, 2010 Share Posted February 9, 2010 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. HTH Teamtomic Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009207 Share on other sites More sharing options...
bgbs Posted February 9, 2010 Author Share Posted February 9, 2010 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']; Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009213 Share on other sites More sharing options...
thewooleymammoth Posted February 9, 2010 Share Posted February 9, 2010 Can you give td a class? i would just do <td><span class='$class'>$info</span></td> Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009254 Share on other sites More sharing options...
thewooleymammoth Posted February 9, 2010 Share Posted February 9, 2010 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'> Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009256 Share on other sites More sharing options...
teamatomic Posted February 9, 2010 Share Posted February 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009262 Share on other sites More sharing options...
bgbs Posted February 9, 2010 Author Share Posted February 9, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009443 Share on other sites More sharing options...
bgbs Posted February 9, 2010 Author Share Posted February 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191427-need-help-displaying-values-in-different-color/#findComment-1009580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.