kat35601 Posted October 28, 2014 Share Posted October 28, 2014 I need help changing the back ground color of a field. the below code sets the background color of my field to red(I have highlighted the code in red that does this.) What I want to do is change that color when the sql field WIP_master.uompScheduleColor changes.So i think I would want an if statement to do this but I am not sure where to start since the field I will be looking at is in the sql statment. WIP_master.uompScheduleColor data looks like this: CRIMSON NEON BLUE PINK SILVER GREEN YELLOW my code so far: <html> <head> <title>PHP SQL Test</title> </head> <body> <p> Status Screen </p> <?php $bgcolor="#FF0000"; $connect =odbc_connect("REMOVED"); if(!$connect) { exit("Connection Failed: " . $connect); } $sql=" SELECT distinct WIP_master.uompScheduleNumber,WIP_master.uompScheduleColor ,WIP_locations.location_name ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '2' ) as Printed ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '3' ) as Audited ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '9' ) as Shortage ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '10' ) as Shortage_Prt ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '11' ) as Red ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '12' ) as Neon ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '20' ) as QC_Hold FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations ON WIP_master.location = WIP_locations.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status ON WIP_master.STATUS = WIP_status.STATUS order by WIP_master.uompScheduleNumber " ; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } echo "<table><tr>"; echo "<th>ScheduleNumber</th>"; echo "<th>Location</th>"; echo "<th>Printed</th>"; echo "<th>Audited</th>"; echo "<th>Shortage</th>"; echo "<th>Shortage_Prt</th>"; echo "<th>Red</th>"; echo "<th>Neon</th>"; echo "<th>QC_Hold</th>"; while (odbc_fetch_row($result)) { $uompScheduleNumber=odbc_result($result,"uompScheduleNumber"); $location_name=odbc_result($result,"location_name"); $Printed=odbc_result($result,"Printed"); $Audited=odbc_result($result,"Audited"); $Shortage=odbc_result($result,"Shortage"); $Shortage_Prt=odbc_result($result,"Shortage_Prt"); $Red=odbc_result($result,"Red"); $Neon=odbc_result($result,"Neon"); $QC_Hold=odbc_result($result,"QC_Hold"); echo "<tr><td bgcolor=$bgcolor >$uompScheduleNumber</td>"; echo "<td>$location_name</td>"; echo "<td>$Printed</td>"; echo "<td> $Audited</td>"; echo "<td> $Shortage</td>"; echo "<td> $Shortage_Prt</td>"; echo "<td> $Red</td>"; echo "<td> $Neon</td>"; echo "<td> $QC_Hold</td>"; } odbc_close($connect); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/292122-change-background-color-of-a-field-with-mssql-an-if-statement-and-variable/ Share on other sites More sharing options...
Ch0cu3r Posted October 28, 2014 Share Posted October 28, 2014 Are they the names of the colors you want to change the cell background color to? I assume you could do while (odbc_fetch_row($result)) { ... $bgcolor = odbc_result($result, "uompScheduleColor"); // get the WIP_master.uompScheduleColor value from the result set. Save it to $bgcolor echo "<tr><td bgcolor=$bgcolor >$uompScheduleNumber</td>"; // set background color to $bgcolor ... } Link to comment https://forums.phpfreaks.com/topic/292122-change-background-color-of-a-field-with-mssql-an-if-statement-and-variable/#findComment-1495058 Share on other sites More sharing options...
kat35601 Posted October 29, 2014 Author Share Posted October 29, 2014 worked perfect thanks Link to comment https://forums.phpfreaks.com/topic/292122-change-background-color-of-a-field-with-mssql-an-if-statement-and-variable/#findComment-1495110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.