如何突出显示4列中的最小值?mysql+;PHP

如何突出显示4列中的最小值?mysql+;PHP,php,mysql,Php,Mysql,以及要遵循的PHP $result = mysql_query("SELECT * FROM pricing ORDER BY Product ASC LIMIT 5000"); $counter=0; $btncounter=0; while($row=mysql\u fetch\u数组($result)){ $counter=$counter+1; $btncounter=$btncounter+1; 打印“\n”; 打印“.$row['Product']”。\n; 打印“.$row['P

以及要遵循的PHP

$result = mysql_query("SELECT * FROM pricing ORDER BY Product ASC LIMIT 5000");
$counter=0;
$btncounter=0;
while($row=mysql\u fetch\u数组($result)){
$counter=$counter+1;
$btncounter=$btncounter+1;
打印“\n”;
打印“.$row['Product']”。\n;
打印“.$row['Price1']”。\n;
打印“.$row['Price2']”。\n;
打印“.$row['Price3']”。\n;
打印“.$row['Price4']”。\n;
我想用红色/粗体/或下划线显示最低价格,我想知道如何使用Least()函数,大致如下: 最低价格(价格1、价格2、价格3、价格4)

if($row['Price1']==LEAST(Price1、price2、price3、price4)
{以红色打印“价格1”\n;}
还是沿着那条路线

谁能给我指出正确的方向吗

简-我试着利用你的答案: 但我的结果都显示为红色, 我的mysql查询与您的相同

if($row['Price1'] == LEAST(price1, price2, price3, price4)
{print "<td>Price 1 in Red</td>\n";}
while($row=mysql\u fetch\u array($result))
{
$counter=$counter+1;
$btncounter=$btncounter+1;
打印“\n”;
打印“.$row['ID']”。\n;
打印“.$row['Product']”。\n;
if($result['price1']=$result['minister_price']){print.$row['price1'].“\n”}else{print.$row['price1'.“\n”}
如果($result['price2']=$result['miniminal_price']){print.$row['price2'].“\n”}其他{print.$row['price2'.“\n”}
if($result['price3']=$result['minister_price']){print.$row['price3'].“\n”}else{print.$row['price3'.“\n”}
如果($result['price4']=$result['miniminal_price']){print.$row['price4'].“\n”}其他{print.$row['price4'.“\n”}
打印“.”行[“上次更新”]。“\n”;
}

我加上其他的行吗

2013年10月10日更新-使其正常工作(某种程度上)

使用: if($row['Price1']=$row['miniminable_price']){print.'$row['Price1'].“\n”}其他{print.'$row['Price1'.“\n”}


但它只在所有四种价格都有值时才起作用-如果没有值怎么办?

您可以使用
排序功能将它们从
低到高排序

while($row = mysql_fetch_array($result))
{
$counter=$counter+1;
$btncounter=$btncounter+1;
print "<tr>\n";
print "<td>".$row['ID']."</td>\n";
print "<td>".$row['Product']."</td>\n";
if ($result['price1'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price1']."</span></td>\n"; } else {print "<td>".$row['price1']."</td>\n";}
if ($result['price2'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price2']."</span></td>\n"; } else {print "<td>".$row['price2']."</td>\n";}
if ($result['price3'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price3']."</span></td>\n"; } else {print "<td>".$row['price3']."</td>\n";}
if ($result['price4'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price4']."</span></td>\n"; } else {print "<td>".$row['price4']."</td>\n";}
print "<td>".$row['Last_updated']."</td>\n";

您可以使用
sort
功能将它们从
低到高进行排序

while($row = mysql_fetch_array($result))
{
$counter=$counter+1;
$btncounter=$btncounter+1;
print "<tr>\n";
print "<td>".$row['ID']."</td>\n";
print "<td>".$row['Product']."</td>\n";
if ($result['price1'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price1']."</span></td>\n"; } else {print "<td>".$row['price1']."</td>\n";}
if ($result['price2'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price2']."</span></td>\n"; } else {print "<td>".$row['price2']."</td>\n";}
if ($result['price3'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price3']."</span></td>\n"; } else {print "<td>".$row['price3']."</td>\n";}
if ($result['price4'] == $result['smallest_price']) { print "<td><span style='color:red'>".$row['price4']."</span></td>\n"; } else {print "<td>".$row['price4']."</td>\n";}
print "<td>".$row['Last_updated']."</td>\n";

您应该在查询中使用Mysql least函数:

$values = sort(array($row['Price1'], $row['Price2'], $row['Price3'], $row['Price4'], SORT_NUMERIC));

echo $values[0]; //lowest price

您应该在查询中使用Mysql least函数:

$values = sort(array($row['Price1'], $row['Price2'], $row['Price3'], $row['Price4'], SORT_NUMERIC));

echo $values[0]; //lowest price
使用

$counter=0;
$btncounter=0;
while($row=mysql\u fetch\u数组($result)){
$counter=$counter+1;
$btncounter=$btncounter+1;
打印“\n”;
打印“.$row['Product']”。\n;
$prices=数组($row['Price1']、$row['Price2']、$row['Price3']、$row['Price4']);
$minimum_price=min($prices)
foreach(价格为$price){
$price_text=$price;
如果($price==$minimum_price){
$price_text=“$price_text”;
}
打印“.$price\u文本”。\n”;
}
使用什么

$counter=0;
$btncounter=0;
while($row=mysql\u fetch\u数组($result)){
$counter=$counter+1;
$btncounter=$btncounter+1;
打印“\n”;
打印“.$row['Product']”。\n;
$prices=数组($row['Price1']、$row['Price2']、$row['Price3']、$row['Price4']);
$minimum_price=min($prices)
foreach(价格为$price){
$price_text=$price;
如果($price==$minimum_price){
$price_text=“$price_text”;
}
打印“.$price\u文本”。\n”;
}

Hi Jan,我试图实现您的答案,但我的结果都显示为红色,-我再次发表了评论。您可以将价格列修改为不为null且默认值为0.00吗?例如:
ALTER TABLE pricing CHANGE price1 price1 DECIMAL(12,2)NOT NULL默认值“0.00”
@CraigDearden现在对您有效吗?如果您接受我的答案那就太好了Hi Jan,我已经尝试实现您的答案,但我的结果都显示为红色,-我再次发表了评论。您能将价格列修改为NOT NULL且默认值为0.00吗?例如:
ALTER TABLE pri更改价格1价格1十进制(12,2)非空默认值“0.00”
@CraigDearden现在对您有效吗?如果您当时接受我的答案,那就太好了
$counter = 0;
$btncounter = 0;
while($row = mysql_fetch_array($result)){
$counter=$counter+1;
$btncounter=$btncounter+1;
print "<tr>\n";
print "<td>".$row['Product']."</td>\n";
$prices = array($row['Price1'],$row['Price2'],$row['Price3'],$row['Price4']);
$minimum_price = min($prices)
foreach ( $prices as $price) {
   $price_text = $price;
   if ($price == $minimum_price) {
      $price_text = "<span style='color:red'>$price_text</span>";
   }
   print "<td>".$price_text."</td>\n";
}