Help needed to change font color based on the value from the

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sankarkarthikeyan
Forum Newbie
Posts: 2
Joined: Fri Sep 30, 2011 10:45 am

Help needed to change font color based on the value from the

Post by sankarkarthikeyan »

This is my coding when a user tries to fetch the info the status value color should change accordingly like

Code: Select all

Not yet open  :Blue
Open             : Green
Processing     : Amber
Closed           : Grey
Here is the complete coding there is no issues in fetching the data s from DB

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>Tickets</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<link href="ticket.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>My search results</h1>
<?php 
include('connect-db.php');

$select = $_POST['id'];
$searchdb = $_POST['searchdb'];

// make the query
$query = "SELECT id, name, issue, status  
FROM data
WHERE $select LIKE '%$searchdb%'ORDER BY id DESC";
$result = @mysql_query($query);
 // run query



if ($result) { // If it ran OK, display the records.

// Table header.
echo '<table id="ticket">
<tr>
<th align="left"><b>Ticket No:</b></th>
<th align="left"><b>Name:</b></th>
<th align="left"><b>Issue:</b></th>
<th align="left"><b>Status:</b></th>
<th align="left"><b>view</b></th></tr>';


// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr><td align="left">' . $row['id'] . '</td>
<td align="left">' . $row['name'] . '</td>
<td align="left">' . $row['issue'] . '</td>	
<td align="left">' . $row['status'] . '</td>
<td align="left"><a href="agentview.php?id=' . $row['id'] . '">View</a></td></tr>';
}

} else {
echo "OOPS I don't have your information .";
}
echo '</table>';

?>
</body>
</html> 

Result should something look like this

[text]ID + Name + Issue + Status + [/text]
[text]12345 + Xyz + Error 404 + Not yet Opened + [/text]
[text]12346 + Xyz + Error 404 + Opened + [/text]
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help needed to change font color based on the value from

Post by Celauran »

I'd define some CSS classes based on the status names.

Code: Select all

<span class="<?php echo $row['status']; ?>"><?php echo $row['status']; ?></span>
Or something to that effect.
sankarkarthikeyan
Forum Newbie
Posts: 2
Joined: Fri Sep 30, 2011 10:45 am

Re: Help needed to change font color based on the value from

Post by sankarkarthikeyan »

Brother can you explain me please
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: Help needed to change font color based on the value from

Post by egg82 »

Try something like this. Replace the values with the colors of your choice and build on that code

Code: Select all

// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if($row['status'] == "open"){
echo '<tr><td align="left">' . $row['id'] . '</td>
 <td align="left"><font color="">' . $row['name'] . '</font></td>
 <td align="left"><font color="">' . $row['issue'] . '</font></td>     
 <td align="left"><font color="">' . $row['status'] . '</font></td>
 <td align="left"><a href="agentview.php?id=' . $row['id'] . '">View</a></td></tr>';
}
}elseif ...
Post Reply