I have a database table named weather which has the following data as below :
Place Temperature
Delhi 30
Bangalore 35
Hyderabad 45
Mumbai 41
Now I fetch these data using php and view them to the client in a table.
Now my question how can I dynamically change row font color based on value i.e the temperature. Shall I have to put the function in server side or in client side using javascript.
I have applied the logic in this manner but have not reached the destination.
//here is my logic that i have put in my php file while fetching the data
if (row["Temperature"] > row["MaxTemperature"]){
this.getStyle().color= "red"; }
else{
this.getStyle().color="yellow";}
//I have set a value for MaximumTemperate
I would do this by creating several css classes, ie:
<style>
.red_temperature {
color: red;
}
.yellow_temperature {
color:yellow;
}
</style>
then in your php, when you generate your client-side code, you add the class to the class="" of the div holding the values you're displaying to the client.
ie:
<?php
// set $classColor variable here based on mysql row
...
echo "<div class='".$classColor."'>74</div>"; // where $classColor = 'yellow_temperature'
?>
This is meant to be a generic starting point, not final code, but just trying to point you in the right direction with the right frame of thinking.
maybe like this, please correct me if i wrong
if ($row['temperature'] > $row['max_temperature'])
{
echo "<font color='red'> red</font>";
}
else { echo" <font color='yellow'>yellow</font>";
}
common.php
<?php
$ArrayList[0] = array('place'=>'Delhi','temperature'=>30);
$ArrayList[1] = array('place'=>'Bangalore','temperature'=>35);
$ArrayList[2] = array('place'=>'Hyderabad','temperature'=>45);
$ArrayList[3] = array('place'=>'Mumbai','temperature'=>41);
$MaxTemperature = 40;
?>
index.php
<?php
require_once('common.php');
$Content = '
<table border="1">
<tr>
<td>Place</td>`
<td>Temperature</td>
</tr>
';
foreach ($ArrayList as $k=>$v)
{
$place = $v['place'];
$temperature = $v['temperature'];
$temperature_color = ($temperature >= $MaxTemperature) ? 'color:red;' : 'color:black;';
$Content .= '
<tr>
<td>'.$place.'</td>
<td style="'.$temperature_color.'">'.$temperature.'</td>
</tr>
';
}
$Content .= '</table>';
echo $Content;
?>
If you are looking for the same, let me know, Ill upload the files
<?php
$Color = "Color:yellow;";
if (Temp>MaxTemp)
{
$Color="Color:red;";
}
?>
<div style='<?php echo $Color ?>'>TempValue</div>
Hi Friends How Is It Set The Color For Work Status ,Project Name And Module Name
$items[]=array(
'title'=>""."Work Status:".$status."
".'Emp Name : '.$Emp->employee_name."[".$position."]"."
".'Project Name : '.$project->project_name."
".'Module Name : '.$module->module_name."",
'start'=>$value->start_date,
'end'=>date('Y-m-d', strtotime('+1 day', strtotime($value->end_date))),
'color'=>'#006699',