-1
$min_cost = min(NULLIF(value, 0))($cost_1, $cost_2, $cost_3, $cost_4);

Some costs on the database return $0.00, so that automatically becomes the $min_cost, even though there is values of more than zero on the other costs

I cant find much info on where the brackets should be on the NULLIF ? anyone help me?

botch
  • 15
  • 5
  • 1
    `NULLIF` is a MySQL function, but you're currently trying to use it as a PHP function. You need to use it inside your MySQL query/ – Amal Murali Apr 22 '14 at 14:27
  • Is it possible for you to filter rows with $0.00 costs out using a WHERE condition? – Joseph B Apr 22 '14 at 14:28
  • can it be used in a WHILE loop? – botch Apr 22 '14 at 14:29
  • while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); $cost_1 = $maxdistance*$row['klm_fare_1'] ; $cost_2 = $maxdistance*$row['klm_fare_2'] ; $cost_3 = $maxdistance*$row['klm_fare_3'] ; $cost_4 = $maxdistance*$row['klm_fare_4'] ; $min_cost = min(NULLIF(value, 0))($cost_1, $cost_2, $cost_3, $cost_4); – botch Apr 22 '14 at 14:29

1 Answers1

0

If you don't want to get rid of the 0 entries through SQL, try using array_filter.

array_filter() should get rid of the 0 entries

$array1 = array($cost_1, $cost_2, $cost_3, $cost_4);

$min_cost = min(array_filter($array1));
Charlie Liu
  • 105
  • 1
  • 9