简体   繁体   中英

how to find the smallest value in each row in html table using php

I have a table with the following:

    6xx     8xx      9xx     11xx      12xx
  1  0.01    0.002    0.004   0.001     0.025
  2  0.025   0.125    0.002   0.01      0.011

I would like to find the Smallest value in each row make that cell to be green color.

For example in 1st the smallest value is 0.001 so i want it to be green color, for second 0.002 is smallest value i want it to be green color.

can any one guide me how to make this ,thanks

my code

<?php

$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxxx';
$dbPassword = 'xxxx';
$dbDatabase = 'xxxx';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");



$ColumnNames = mysql_query("SELECT column_name 
                              FROM information_schema.COLUMNS 
                             WHERE table_name = 'supplierprice' 
                               AND column_name NOT IN ('supp_price_id',
                                                       'region',
                                                       'country',
                                                       'net_id',
                                                       'networkname', 
                                                       'mcc', 
                                                       'mnc', 
                                                       'mnp')")
                or die("mysql error"); 

$columnArray=array();
$i=0;
while($rows=mysql_fetch_array($ColumnNames))
{

$columnArray[]=$rows[0];

echo "<th style='width:67px;' class='. $columnArray[$i] .' >" . $columnArray[$i] . " 
            </th>";
$i++;
}

?>

foreach($columnArray as $value) {


//$columnArray[]=$rows1[0];

echo '<td style="width:67px;font-weight:'.$text.'" id="CPH_GridView1_xxx" width="0px;" class="'.$value.' '.$rows["net_id"].'"><p>'.$rows[$value].'</p></td>';   
}

When you have your array of values for a particular row, you can do something like this:

$lowest = min($values);

Next, when you loop through the values to echo your cells, do something like this:

foreach ($values as $val) {
 if($val == $lowest) {
  $color="green";
 } else {
   $color="";
 }
 echo "<td class=$color>$val</td>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM