Solved

How to format numbers on a recordset

Posted on 2008-06-15
2
244 Views
Last Modified: 2013-12-13
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
Comment
Question by:Caxxcann
2 Comments
 
LVL 3

Accepted Solution

by:
Xorlev earned 50 total points
ID: 21790361
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
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 21790412
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now