abs0lut Posted July 21, 2008 Share Posted July 21, 2008 <?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.. Link to comment https://forums.phpfreaks.com/topic/115786-min-max-in-every-iqid/ Share on other sites More sharing options...
Third_Degree Posted July 21, 2008 Share Posted July 21, 2008 well I didn't read through your entire code, but you will need something like this (I made up the variable names) if ( min( $rows ) == $current_element ) { print '<span style="color:red">' . $current_element . '</span>'; } $rows would be a set of data retrieved from the db stored as an array, and $current_element would be the variable "as" in a foreach loop. Link to comment https://forums.phpfreaks.com/topic/115786-min-max-in-every-iqid/#findComment-595247 Share on other sites More sharing options...
abs0lut Posted July 25, 2008 Author Share Posted July 25, 2008 please read my code, $arr[$iqid][$userid] is multidimensional array.. is it possible to determine the lowest cost in every iqid Link to comment https://forums.phpfreaks.com/topic/115786-min-max-in-every-iqid/#findComment-599818 Share on other sites More sharing options...
abs0lut Posted July 28, 2008 Author Share Posted July 28, 2008 please help me.. bump Link to comment https://forums.phpfreaks.com/topic/115786-min-max-in-every-iqid/#findComment-602122 Share on other sites More sharing options...
KrisMunro Posted July 29, 2008 Share Posted July 29, 2008 It may be easier to add another field within your array called 'lowest' (and 'highest' if you needed one). As you place entries into the array, you just keep a record of which value is lower so that (eg) if ($value < $lastvalue) { $lastvalue = $value; $lowestID = $itemID; } Once the array is created, you alter the 'lowest' entry for the $itemID you collected; make the 'lowest' 1 rather than 0. Then use that definition for changing the colour of your text. There is likely a more efficient way of doing things.. but see how you go with this. Link to comment https://forums.phpfreaks.com/topic/115786-min-max-in-every-iqid/#findComment-602207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.