• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

How to format numbers on a recordset

How do I set a negative number to a red color from a recordset retrived from:

Select table1.ID, table1.Name, Sum(Case When table1.ID = table2.ID and  table2.score1 < 0 Then score1 Else 0 End)
From table1, table2
0
Caxxcann
Asked:
Caxxcann
1 Solution
 
XorlevCommented:
When you retrieve it through PHP, you can do something like this when echoing it:
<?php echo ($mydata < 0) ? '<span style="color:red;">' . $mydata . '</span>' : $mydata; ?>

Open in new window

0
 
Matthew KellyCommented:
It isn't a mysql database that you are selecting from I can tell, but if you were the code below would be what it is.

This would set the bg color to red, but the same concept could be set for the font as well.

You will need to change the mysql syntax to the MSSQL or Access that you are using
$sql = "Select table1.ID, table1.Name, Sum(Case When table1.ID = table2.ID and  table2.score1 < 0 Then score1 Else 0 End)
From table1, table2";
$result = mysql_query($sql,$db);
if ($result && mysql_num_rows($result) > 0 )
{
	echo "<table cellpadding=0 cellspacing=0>";
	for ($i=0;$i<mysql_num_rows($result);$i++)
	{
		$id = mysql_result($result,0,"ID")
		$name = mysql_result($result,0,"Name")
		$score = mysql_result($result,0,2);
		if ( $score < 0 )
		{
			echo "<tr style=\"background-color:red\">";
		}
		else { echo "<tr>"; }
 
		echo "<td>".$id."</td><td>".$name."</td><td>".$score."</td>";
		
		echo "</tr>";
	}
	echo "</table>";
}

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now