I have a PHP page that displays in a table budget vs. actual figures from a MySQL db. I want to add logic where if the actual is greater than the budget, the data is displayed in red, otherwise display in black. -
...
-
while ($myrow = mysql_fetch_array($result))
-
{
-
echo "<tr><td>".$myrow["facility"]."</td>";
-
echo "<td align=right>$".number_format($myrow["sw_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["sw_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>".$myrow["pd_actual"]."</td>";
-
echo "<td align=right>".$myrow["pd_budget"]."</td></tr>";
-
}
-
echo "</tr></table>";
-
...
-
I want something like this: -
If ($myrow["sw_actual"] > $myrow["sw_budget"])
-
{ fontcolor=red;
-
}
-
I tried this prior to the While code, and got an error with the 'fontcolor=red' line. Parse error: parse error, unexpected '=' in /usr/local/php_classes/swb_2007_01.php on line 88.
I tried 'fontcolor: red' as well as 'fontcolor red', but get a parse error for each.
Is my If statement incorrect? Should it be placed elswhere?
TIA,
jej1216
4 1560
I have a PHP page that displays in a table budget vs. actual figures from a MySQL db. I want to add logic where if the actual is greater than the budget, the data is displayed in red, otherwise display in black. -
...
-
while ($myrow = mysql_fetch_array($result))
-
{
-
echo "<tr><td>".$myrow["facility"]."</td>";
-
echo "<td align=right>$".number_format($myrow["sw_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["sw_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>".$myrow["pd_actual"]."</td>";
-
echo "<td align=right>".$myrow["pd_budget"]."</td></tr>";
-
}
-
echo "</tr></table>";
-
...
-
I want something like this: -
If ($myrow["sw_actual"] > $myrow["sw_budget"])
-
{ fontcolor=red;
-
}
-
I tried this prior to the While code, and got an error with the 'fontcolor=red' line. Parse error: parse error, unexpected '=' in /usr/local/php_classes/swb_2007_01.php on line 88.
I tried 'fontcolor: red' as well as 'fontcolor red', but get a parse error for each.
Is my If statement incorrect? Should it be placed elswhere?
TIA,
jej1216
try this: -
...
-
while ($myrow = mysql_fetch_array($result))
-
{
-
If ($myrow["sw_actual"] > $myrow["sw_budget"])
-
{
-
$style="color:red;";
-
}
-
-
echo "<tr><td>".$myrow["facility"]."</td>";
-
echo "<td align=right>$".number_format($myrow["sw_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right style='".$style."'>$".number_format($myrow["sw_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["ben_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_actual"], 0, '.', ',')."</td>";
-
echo "<td align=right>$".number_format($myrow["cl_budget"], 0, '.', ',')."</td>";
-
echo "<td align=right>".$myrow["pd_actual"]."</td>";
-
echo "<td align=right>".$myrow["pd_budget"]."</td></tr>";
-
}
-
echo "</tr></table>";
-
good luck
Thanks - that was it. I had to add an else statement to keep all actuals to show red: -
while ($myrow = mysql_fetch_array($result))
-
{
-
if ($myrow["sw_actual"] > $myrow["sw_budget"]) {
-
$style1="color:red;"; }
-
else {
-
$style1="color:black;"; }
-
-
if ($myrow["ben_actual"] > $myrow["ben_budget"]) {
-
$style2="color:red;"; }
-
else {
-
$style2="color:black;"; }
-
-
if ($myrow["cl_actual"] > $myrow["cl_budget"]) {
-
$style3="color:red;"; }
-
else {
-
$style3="color:black;"; }
-
-
if ($myrow["pd_actual"] < $myrow["pd_budget"]) {
-
$style4="color:red;"; }
-
else {
-
$style4="color:black;"; }
-
This works, but the code looks clunky - is there a more elegant code to use?
TIA,
jej1216
You can use Ternary Operator.
[PHP]while ($myrow = mysql_fetch_array($result))
{
$style1 = ($myrow["sw_actual"] > $myrow["sw_budget"]) ? "color:red;" : "color:black;";
$style2 = ($myrow["ben_actual"] > $myrow["ben_budget"]) ? "color:red;" : "color:black;";
$style3 = ($myrow["cl_actual"] > $myrow["cl_budget"]) ? "color:red;" : "color:black;";
$style4 = ($myrow["pd_actual"] < $myrow["pd_budget"]) ? "color:red;" : "color:black;";
}[/PHP]
You can use Ternary Operator.
[PHP]while ($myrow = mysql_fetch_array($result))
{
$style1 = ($myrow["sw_actual"] > $myrow["sw_budget"]) ? "color:red;" : "color:black;";
$style2 = ($myrow["ben_actual"] > $myrow["ben_budget"]) ? "color:red;" : "color:black;";
$style3 = ($myrow["cl_actual"] > $myrow["cl_budget"]) ? "color:red;" : "color:black;";
$style4 = ($myrow["pd_actual"] < $myrow["pd_budget"]) ? "color:red;" : "color:black;";
}[/PHP]
Thanks - that is pretty slick code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Simon Harvey |
last post by:
Hello Chaps,
Me and a collegue have been talking about where the best place to put
business logic is.
I think that the best place is where Microsoft suggest - in a seperate
business logic...
|
by: jvyyuie |
last post by:
// My email is jvyyuie@hotmail.com
// I want to make some friends and discuss about programing.
#include "stdafx.h"
#include <malloc.h>
#include <string.h>
#define sec1...
|
by: Steve Jorgensen |
last post by:
First, an example - today, I wanted to print out the parameter values in a
querydef object at a break point in the code for subsequent manual debugging
of the query. In the past, I would have had...
|
by: Mr. Mountain |
last post by:
In the following code I simulate work being done on different threads by
sleeping a couple methods for about 40 ms. However, some of these methods
that should finish in about 40 -80 ms take as long...
|
by: Chris Kettenbach |
last post by:
Hi I am designing an ASP.net app. Just wanted some opinions on code behind
options. My idea is to have a code behind file that the controls will
reference and have ascx files for the controls. ...
|
by: Brett |
last post by:
Say I develop an application that has an SQL Server 2000 back end with
ASP.NET front end. All the business logic is in the aspx pages. I want to
sell this as a package that some one can install...
|
by: Phillip N Rounds |
last post by:
I'm working on a UserControl ( ASP.NET 1.1, C#, VS 2003), where I can't
manage the state of multiple controls correctly.
The controls have the following constraints
1: It has two possible...
|
by: rn5a |
last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with
the IDs 'txt1' & 'txt2' respectively. To use this user control in an
ASPX page, the following Register directive will be...
|
by: stephenrussett |
last post by:
Ok i what i am trying to do is:
I have a query that pumps out information like this:
(1) (2) (3) (4) (5)
1 1 Cooper Street NS...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |