Page 1 of 1

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

Posted: Fri Sep 30, 2011 11:09 am
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]

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

Posted: Fri Sep 30, 2011 11:15 am
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.

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

Posted: Fri Sep 30, 2011 12:04 pm
by sankarkarthikeyan
Brother can you explain me please

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

Posted: Sat Oct 01, 2011 11:21 pm
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 ...