The following shows a table drawn from a databse (MySql in this case) using php to give red fonts for negative number and blue for positive numbers. The rows are also in alternate colors. You need t ofill in your own data and parameters for the database, of course.
<table border=0 bgcolor=white width="502" cellpadding="0"
cellspacing="0">
<tr><td>
<table border="0" cellpadding="2" cellspacing="1" width="100%">
<tr bgcolor="336699">
<td align=middle id="header">a</td>
<td align=middle id="header">b</td>
<td align=middle id="header">c</td>
<td align=middle id="header">d</td>
<td align=middle id="header">e</td>
</tr>
<?php
mysql_connect(localhost,user,password);
$database="your_database";
@mysql_select_db("$database") or die( "Unable to select database");
$table="your_table";
$query="select * from $table
where $table.data1=something AND $table.data2 >0 order by this_order";
$result=mysql_query($query);
mysql_close();
/*Display Results*/
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$a=mysql_result($result,$i,"a");
$b=mysql_result($result,$i,"b");
$c=mysql_result($result,$i,"c");
$d=mysql_result($result,$i,"d");
$e=mysql_result($result,$i,"e");
//Alternate row colors in our table
print ($i % 2) ? "<tr bgcolor=\"CCCCCC\">" : "<tr
bgcolor=\"BEEFFF\">";
print "<td align=right>$a</td>";
print "<td align=right>$b</td>";
print "<td align=right>$c</td>";
print "<td align=right>$d</td>";
print "<td align=right><span style=\"color:";
if ($d > 0){
print "blue";
} else {
print "red";
}
print ";\">$e</span></td>";
++$i;
}
?>
</table>
Newbie Notes #10 - Generating drop downs Categories : PHP , MySQL , HTML , Beginner Guides , Databases Paginator - a class that can help you to split MySQL database query result sets to pages. Categories : MySQL , Databases , HTML , PHP bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases , MySQL , Complete Programs , PHP , Databases Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL , Date Time , PHP , Databases GroupIT Engine v1.00rc1
Categories : PHP , Content Management , MySQL , Databases mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP , Beginner Guides , MySQL , HTML and PHP , Databases Simple function to return the number of days in a time span between 2 given dates. Categories : PHP , Date Time , MySQL , Databases How to thread a list of messages in database
and show it in a treelike structure Categories : PHP , MySQL , Databases [PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more. Categories : PHP , PHP Classes , Databases , MS SQL Server , MySQL Newbie Notes #4 - Trapping dumb MySQL query errors Categories : PHP , Databases , MySQL , Debugging , Beginner Guides Creating thumbnails from MySQL Blobs online Categories : PHP , MySQL , Graphics , HTML and PHP , Databases email new items in db Categories : PHP , Email , Databases , MySQL , Beginner Guides Message of the Day - Random Message (Needs MySQL!) Categories : Databases , HTML and PHP , PHP , MySQL TAB_STRUCT Class: Is supporting Class for the DBXML Class Categories : PHP , PHP Classes , MySQL , XML , Databases