<?php
session_start();
include 'config.php';
$post = $_GET['post'];
$slected = array();
if(isset($_POST['checkb'])){
if(count($_POST['sa']) > 0){
$do2 = mysql_query("UPDATE ptable SET status='updated' WHERE id='$post'") or die(mysql_error());
if($do2){
echo 'updated';
}
foreach($_POST['sa'] as $awrd) {
$result = mysql_query("UPDATE ctable SET awarded='yes' WHERE id='$awrd'") or die(mysql_error());
$slected[] = $awrd;
if($result){
echo 'awarded'.$usersid;
}
}
}
} else{
$result = mysql_query("SELECT status FROM ptable WHERE id=$post") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$status=$row['status'];
}
if($status!='updated'){
?>
<form method="post" name="formk" action="<?= $_SERVER['PHP_SELF']. '?' . $_SERVER['QUERY_STRING'] ?>">
<?php
$result = mysql_query("SELECT cid, iqid, cost, usersid FROM ctable WHERE post=$post");
while ($row = mysql_fetch_array($result))
{
$arr[$row['iqid']][$row['usersid']] = $row['cost'];
$arr2[$row['iqid']][$row['usersid']] = $row['cid'];
$uid[] = $row['usersid'];
}
$uid = array_unique($uid);
$qid = array_keys($arr);
$query = "SELECT MIN(cost), MAX(cost) FROM ctable WHERE post=$post";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$min=$row['MIN(cost)'];
$max=$row['MAX(cost)'];
}
echo '<table><tr><td></td>';
foreach($uid as $userid) echo "<td>$userid</td>";
echo '</tr>';
foreach($qid as $iqid)
{
echo "<tr><td>$iqid</td>";
foreach($uid as $userid)
{
if (isset($arr[$iqid][$userid]))
{
if($min==$arr[$iqid][$userid]){
echo "<td bgcolor=\"#FFFF00\">".$arr[$iqid][$userid]."<input type='checkbox' name='sa[]' value='{$arr2[$iqid][$userid]}'></td>";
}else if($max==$arr[$iqid][$userid]){
echo "<td bgcolor=\"#00FF00\">".$arr[$iqid][$userid]."<input type='checkbox' name='sa[]' value='{$arr2[$iqid][$userid]}'></td>";
}else{
echo "<td>".$arr[$iqid][$userid]."<input type='checkbox' name='sa[]' value='{$arr2[$iqid][$userid]}'></td>";
}
}
else echo "<td></td>";
}
echo "</tr>";
}
echo '</table>';
echo '<input type="submit" name="checkb" />';
echo'</form>';
}
}
?>
i want the lowest cost in every iqid to have background color #FF0000
any help would be appreciated.