Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone...am new in php and i have a few questions here...

1.I'm trying to find the mode value for the following query in mysql. The query ie Kra,Year,Max(Rating1),Max(Rating2),Max(Rating3)...the task is to display the mode ie Total_Rating.There are 2 types of rating ie "Good" or "Problematic"..if Max(Rating1)="Good", Max(Rating2)="Good",Max(Rating3)="Problematic", the mode or Total_Rating="Good".Below is the coding but it didn't display as what suppose to...please advise...
SQL
SELECT Max(Max(Rating1),Max(Rating2),Max(Rating3)) as mode FROM progress GROUP BY (Max(Rating1),Max(Rating2),Max(Rating3)) ORDER BY mode DESC LIMIT 1;


2.After getting the Total_Rating, i want to display the Total_Rating as color...The coding as follows...
PHP
<?php
$con=mysqli_connect("localhost","pqa","","pq");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM total_rating");
echo "<table border="1">
<tr>
<th>KRA(Key Result Areas)</th>
<th>Total Rating</th>
<th>Status</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Kra'] . "</td>";
$class = ($row['mode'] == 'good') ? 'green' : 'red';
echo "<td class="$class">" . $row['Total_Rating'] . "</td>";
echo "</tr>";
}
echo "</table>";

switch ($row['Total_Rating']) { 
case "good"; 
    echo "#008000"; 
    break; 
default;     
    echo "#FF0000"; 
    break;     
} 
mysqli_close($con);
?>

Thanks a lot for your help...
Posted
Updated 10-Oct-14 5:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900