Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Conditional Formatting with MySQL thresholds table
    primarykey
    data
    text
    <p>I want the text colors to change based on the target. Basically anything between 0 and 100 would be green and between 100 and 125 would be yellow and anything beyond 125 would be red. But that's only for 1 specific department. Let's say I have someone in another department that doesn't have the same threshold then anything below 150 would be green and etc...</p> <p>This is the code I am using.</p> <pre><code>while ($row = mysql_fetch_array($query)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;".$row['Department']."&lt;/td&gt;"; if (($row['Hold'] &gt;= 0) &amp;&amp; ($row['Handle_Time'] &lt;= 100)) { echo "&lt;td style=\"color:#005e20; font-weight: bold;\"&gt;".$row['Handle_Time']."&lt;/td&gt;"; //green } elseif (($row['Handle_Time'] &gt;= 100.01) &amp;&amp; ($row['Handle_Time'] &lt;= 124.99)) { echo "&lt;td style=\"color:#e77904; font-weight: bold;\"&gt;".$row['Handle_Time']."&lt;/td&gt;"; // yellow } elseif ($row['Handle_Time'] &gt;= 125) { echo "&lt;td style=\"color:#FF0000; font-weight: bold;\"&gt;".$row['Handle_Time']."&lt;/td&gt;"; // red } else { echo "&lt;td&gt;".$row['Hold']."&lt;/td&gt;"; // no color } echo "&lt;/tr&gt;"; } </code></pre> <p>What I have in mind is a MySQL table that has the threshold of each department. Each person has a department code and I want the department to match the target and change color accordingly.</p> <p>Here's the target table called <code>stats_threshold</code></p> <pre><code> Department Metric Target Yellow Red ------------------------------------------------------ WR Handle_Time 100.00 124.99 125.00 CA Handle_Time 100.00 124.99 125.00 RET Handle_Time 120.00 169.99 170.00 CET Handle_Time 200.00 249.99 250.00 </code></pre> <p>How do I query the department code to match the department in my table then <code>echo</code> the target and threshold. Expected result (The color column doesn't exist, it's only to show what the text color should be)</p> <pre><code> Department Handle_Time Colors ------------------------------------------------------ CA 66 GREEN CA 118 YELLOW CA 137 RED WR 96 GREEN WR 102 YELLOW WR 143 RED RET 119 GREEN RET 163 YELLOW RET 240 RED CET 199 GREEN CET 201 YELLOW CET 251 RED </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload