Jump to content

[SOLVED] PHP to do this???


web.dork

Recommended Posts

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);

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/
Share on other sites

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>";
}

Link to comment
https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/#findComment-219349
Share on other sites

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  8)

Link to comment
https://forums.phpfreaks.com/topic/45183-solved-php-to-do-this/#findComment-219353
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.