tigomark Posted September 11, 2007 Share Posted September 11, 2007 Hello all, I am trying to dynamically generate bgcolors with to help populate some information for a site. Here is the code snipets function addColor(){ for ($a = 1; $a <= 12; $a++) $this->color1 = "#ff0000"; $this->color2 = "#00ff00"; $this->color3 = "#0000ff"; $this->color4 = "#ffff00"; $this->color5 = "#ff00ff"; $this->color6 = "#f3e3d3"; $this->color7 = "#11ee33"; $this->color8 = "#ab55e1"; $this->color9 = "#12c522"; $this->color10 = "#f033a9"; $this->color11 = "#44e2f1"; $this->color12 = "#3af422"; //V4 Pre-Trip Colors if ($data["zonename$j"] == "BRAKES"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color1); }else if ($data["zonename$j"] == "RIGHT FRONT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color2); }else if ($data["zonename$j"] == "REAR LIGHTING"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color3); }else if ($data["zonename$j"] == "LEFT REAR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color4); }else if ($data["zonename$j"] == "INSIDE BUS"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color5); }else if ($data["zonename$j"] == "FRONT LIGHTING"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color6); }else if ($data["zonename$j"] == "ENTERING BUS"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color7); }else if ($data["zonename$j"] == "ENGINE COMPARTMENT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color8); }else if ($data["zonename$j"] == "DRIVERS SEAT AREA"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color9); }else if ($data["zonename$j"] == "RIGHT REAR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color10); }else if ($data["zonename$j"] == "LEFT FRONT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color11); } // Truck Pre-Trip colors else if ($data["zonename$j"] == "TRAILER FRONT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color1); }else if ($data["zonename$j"] == "TRAILER LEFT REAR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color2); }else if ($data["zonename$j"] == "TRAILER RIGHT REAR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color4); }else if ($data["zonename$j"] == "TRAILER FRONT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color5); }else if ($data["zonename$j"] == "FRONT"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color6); }else if ($data["zonename$j"] == "LF"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color7); }else if ($data["zonename$j"] == "ENGINE"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color8); }else if ($data["zonename$j"] == "RF"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color9); }else if ($data["zonename$j"] == "INSIDE CAB"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color10); }else if ($data["zonename$j"] == "LR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color11); }else if ($data["zonename$j"] == "RR"){ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color12); }else{ $background['$a'] = sprintf("bgcolor=\"%s\"", $this->color12); } } Then the code is populated in another function $reporthtml .= sprintf("<td><div class=\"idColumn\">%d</div></td>\n", $this->rowNumber($rownum)); $reporthtml .= sprintf("<td>%s</td><td>%s</td><td>%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td><td %s title=\"%s\">%s</td></tr>\n", $data->inspType, $data->assetName, $data->inspID, $background['$a'], $data->zonename1, $data->timestamp1, $background['$a'], $data->zonename2, $data->timestamp2, $background['$a'], $data->zonename3, $data->timestamp3, $background['$a'], $data->zonename4, $data->timestamp4, $background['$a'], $data->zonename5, $data->timestamp5, $background['$a'], $data->zonename6, $data->timestamp6, $background['$a'], $data->zonename7, $data->timestamp7, $background['$a'], $data->zonename8, $data->timestamp8, $background['$a'], $data->zonename9, $data->timestamp9, $background['$a'], $data->zonename10, $data->timestamp10, $background['$a'], $data->zonename11, $data->timestamp11 ); $rownum++; Currently all of the other information is populated but the backgrounds are not populating. Any help would be great Quote Link to comment https://forums.phpfreaks.com/topic/68783-solved-populating-table-information/ Share on other sites More sharing options...
recklessgeneral Posted September 11, 2007 Share Posted September 11, 2007 Hi, Change $background['$a'] to $background[$a] everywhere and see what that does. By using the single quotes, the $a is not expanded so the key to the array will be the literal string '$a'. I was going to suggest using double-quotes instead (i.e. $background["$a"]) which would expand $a, but is unnecessary, unless you specifically want a string key instead of a number. A minor point, but your addColor function reassigns color1 through color12 each time through the for loop, which isn't very efficient. I would at least put the assignments before the loop declaration: function addColor(){ $this->color1 = "#ff0000"; // etc for ($a = 1; $a <= 12; $a++) { //V4 Pre-Trip Colors // etc } Just noticed, you're also missing the { } from your for loop. This will cause the first statement after the for loop declaration to be run 12 times, and the rest of the code to be run once, which would also cause problems. Cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/68783-solved-populating-table-information/#findComment-345828 Share on other sites More sharing options...
tigomark Posted September 11, 2007 Author Share Posted September 11, 2007 Thank you Darren, Thanks for catching some of the silly things I was doing there. Unfortunately still not populating. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/68783-solved-populating-table-information/#findComment-346054 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2007 Share Posted September 11, 2007 it looks like you are calling the function function addColor() without $data, but then you use $data in the function. you probably need to pass $data to the function: function addColor($data) { // Now you can use $data } Quote Link to comment https://forums.phpfreaks.com/topic/68783-solved-populating-table-information/#findComment-346073 Share on other sites More sharing options...
tigomark Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks Blue, Again another little miss that needed to be done. Still not populating but Thanks for the catch Quote Link to comment https://forums.phpfreaks.com/topic/68783-solved-populating-table-information/#findComment-346077 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.