?
Solved

How to format numbers on a recordset

Posted on 2008-06-15
2
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
Xorlev earned 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

801 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