Code: Select all
<?php
session_start();
require_once('inc/constant.php');
require_once('inc/function.php'); //basic functions
db_on();
$table = 'mytable';
// sending query
$sql = "SELECT `name` AS `Name`, `yesterday` AS `Yesterday`, `today` AS `Today`, `difference` AS `Difference`, `quota` AS `Quota`, `date` AS `Date` FROM {$table} WHERE `active` = 1 ";
$res=mysql_query($sql,_sql);
if (!$res) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($res);
echo "<table border='1' align='center'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($res);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
$i=0;
while($row = mysql_fetch_row($res)){
echo "<tr>";
if (($i%2)==0){
foreach($row as $cell)
echo "<td><font color='FF0000'>$cell</font></td>";
}
else{
foreach($row as $cell)
echo "<td><font color='0000FF'>$cell</font></td>";
}
$i++;
echo "</tr>\n";
}
mysql_free_result($res);
?>
However I actually would like to have the rows red only if the value in 'difference' is negative (ie -1000) and have it blue only if the value in 'difference' is positive (ie 1000) and if it is 0, it can stay black.
Is there a way to do this?
Also, is there a way to calculate a value to show up in the table like (in layman's terms:)
'difference' = 'today' - 'yesterday' - 'difference' from the above query,
instead of the original value in the database, without changing the value in the database?