我有一张 table ,上面有:

    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

我想从该列中找到“最小值”,使该列为绿色。

例如在第一个最小值是0.001,所以我希望它是绿色,第二个最小值是0.002,我希望它是绿色。

任何人都可以指导我如何做到这一点,谢谢

下面的代码是我如何从数据库中选择它并在表中显示int的代码
<?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>';
}

最佳答案

您的问题的一个答案可能是:

1-通过sql查询提取每列的最小值,如下所示:

$res1=mysql_query('select min(6xx) as min6, min(8xx)as min8, min(9xx) as min9, min(11xx)as min11, min(12xx) as min12 from tbl_name');

$rec1=mysql_fetch_array($res1);

$min6=rec1['min6'];

$min8=rec1['min8'];

$min9=rec1['min9'];

....

2-当您在html中获取信息时,应检查该值是否类似于min,然后背景(某些CSS)变为绿色:
$res=mysql_query('select * from tbl_name');
echo "<table>";
foreach($rec=mysql_fetch_array($res))
{
echo "<tr>"
    echo "<td";
        if($rec['6xx']==$min6) echo "class='green_cell' ";
    echo "";
        echo $rec['6xx'];
    echo "</td>";
    ....

echo "</tr>"

关于php - 如何使用PHP从多个列中选择最小值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24881786/

10-13 03:15