web.dork Posted April 1, 2007 Share Posted April 1, 2007 Question.... Let's say I have a MySQL database with a field names 'Status'; this field only has two possible results, 'Active' and 'Inactive'. When the query is made and the results for the rows are pulled into preformatted tables I have coded, what is the correct way to CSS color the text, Red for Inactive and Green for active? I have a linked CSS to the results page, so should I create a CSS class and somehow construct an equality statement in PHP for the var $row[status], like to check if it is either literally 'Active' or 'Inactive', and then assign new vars with the appropriate class name to precede the text? My code: <? require ('login555.php'); //$sql = 'SELECT * FROM `Clients` ORDER BY `Clients` . `lastupdated` ASC LIMIT 1 '; $query = mysql_query("SELECT * FROM Clients ORDER BY id DESC"); echo "<link href=styles/main_style2.css rel=stylesheet type=text/css />"; echo "<center><table width=800 class=form_bg><tr><td width=100 class=w_txt>ID #</td><td width=100 class=w_txt>Last Name</td><td width=100 class=w_txt>First Name</td><td width=100 class=w_txt>Rep</td><td width=100 class=w_txt>Hours</td><td width=100 class=w_txt>Status</td></tr></table></center>"; while ($row=mysql_fetch_array($query)) { echo "<center><table width=800 border=1>"; echo "<tr><td width=100px><a href='http://www.mysite.com/query.php?id=$row[id]'>$row[id]</a></td>"; echo "<td width=100><div align=left class=main_txt>$row[lastname]</td></div><td width=100><div align=left class=main_txt>$row[firstname]</td></div><td width=100><div align=left class=main_txt>$row[rep]</td><td width=100><div align=left class=main_txt>$row[hours]</td></div><td width=100><div align=left class=main_txt>$row[status]</td></div></div></tr></table></center>"; } mysql_close($link); ?> Quote Link to comment https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/ Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 i would change echo "<td width=100><div align=left class=main_txt>$row[lastname]</td></div><td width=100><div align=left class=main_txt>$row[firstname]</td></div><td width=100><div align=left class=main_txt>$row[rep]</td><td width=100><div align=left class=main_txt>$row[hours]</td></div><td width=100><div align=left class=main_txt>$row[status]</td></div></div></tr></table></center>"; } to something like echo "<td width=100><div align=left class=main_txt>$row[lastname]</td></div>"; echo "<td width=100><div align=left class=main_txt>$row[firstname]</td></div>"; echo "<td width=100><div align=left class=main_txt>$row[rep]</td>"; echo "<td width=100><div align=left class=main_txt>$row[hours]</td></div>"; if($row[status] == "active") { echo "<td width=100><div align=left class=active>active</td>"; }else{ echo "<td width=100><div align=left class=inactive>inactive</td>"; } echo "</div></div></tr></table></center>"; } Quote Link to comment https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/#findComment-219349 Share on other sites More sharing options...
web.dork Posted April 1, 2007 Author Share Posted April 1, 2007 i would change echo "<td width=100><div align=left class=main_txt>$row[lastname]</td></div><td width=100><div align=left class=main_txt>$row[firstname]</td></div><td width=100><div align=left class=main_txt>$row[rep]</td><td width=100><div align=left class=main_txt>$row[hours]</td></div><td width=100><div align=left class=main_txt>$row[status]</td></div></div></tr></table></center>"; } to something like echo "<td width=100><div align=left class=main_txt>$row[lastname]</td></div>"; echo "<td width=100><div align=left class=main_txt>$row[firstname]</td></div>"; echo "<td width=100><div align=left class=main_txt>$row[rep]</td>"; echo "<td width=100><div align=left class=main_txt>$row[hours]</td></div>"; if($row[status] == "active") { echo "<td width=100><div align=left class=active>active</td>"; }else{ echo "<td width=100><div align=left class=inactive>inactive</td>"; } echo "</div></div></tr></table></center>"; } PERFECT AND SOLVED! .... you da' man of the hour MT!!!! Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/#findComment-219353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.