Page 1 of 1

Second question - Variables in styles based upon database

Posted: Thu Sep 06, 2007 8:41 am
by Brik
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Below is my code so far. What I am attempting to do is to draw a table and populate it with the contents of a mySQL query from a view. Several columns of the view will drive formatting of rows in the table and ultimately how the table itself draws. Lets just start with shading one row based upon the value of one column.

My query contains a column called $sedonly its populated with yes and no (1,0). I want to shade the corresponding row in the output blue or red based upon the 1 or 0 in the retrieved row.

I learned how to color a table thanks to a response to my post http://forums.devnetwork.net/viewtopic. ... 428#415428

I'm not a programmer and am learning so please go easy on me. Any references to examples or documentation of what I am trying to do would be great!

Code: Select all

<?php
include 'config.php';
include 'opendb.php';

$query  = "select *	from output_all";
$result = mysql_query($query);

$result = mysql_query($query) or die('Error, query failed');

// print info in table
echo '<table border="1"><tr>
					<td><b>Top Level</td>
					<td><b>Category</td>
					<td><b>Offering Name</td>
					<td><b>Resource(s) Name(s)</td></tr>';		
			//		<td><b>sedonly</td>
			//		<td><b>classsmb</td>
			//		<td><b>classdepartmental</td>
			//		<td><b>classenterprise</td>
			//		<td><b>underevaluation</td>
			//		<td><b>dropped</td></tr>';

while(list( $toplevel,
						$category,
						$offeringsname, 
						$resnames, 
						$sedonly, 
						$classsmb, 
						$classdepartmental, 
						$classenterprise, 
						$underevaluation, 
						$dropped ) = mysql_fetch_array($result))
{
echo "<tr>  <td style=\"background-color:blue\" >$toplevel</td> 
             <td>$category</td>                    
             <td>$offeringsname</td>              
             <td>$resnames</td></tr>"; 
}
echo '</table>';
echo '<br>';    	
include 'closedb.php';
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Sep 06, 2007 8:53 am
by Zoxive

Code: Select all

//Snip
{
$color = ($sedonly==1)? 'red' : 'blue'; // If $sedonly is 1 set to red, otherwise blue
echo "<tr>  <td style=\"background-color:$color\" >$toplevel</td>
             <td>$category</td>                   
             <td>$offeringsname</td>             
             <td>$resnames</td></tr>";
} 

Posted: Thu Sep 06, 2007 9:00 am
by Brik
WAY COOL, easy fast!!! Fast reply! Many thanks!

Posted: Thu Sep 06, 2007 10:30 am
by s.dot
Brik wrote:WAY COOL, easy fast!!! Fast reply! Many thanks!
Isn't PHP just so AWESOME?