Jump to content

change background color of a field with MSSQL an if statement and variable


Go to solution Solved by Ch0cu3r,

Recommended Posts

 

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>

 

  • Solution

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

...
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.