I am trying to select minimum and maximum value for capacity from MySQL table but whenever I try I get the following error:
Warning: min(): When only one parameter is given, it must be an array
in /campus/campus.php on line 38 Call Stack: 0.0003 352296 1. {main}()
/campus/campus.php:0 0.0124 1654304 2. min() /campus/campus.php:38
Warning: max(): When only one parameter is given, it must be an array
in /campus/campus.php on line 39 Call Stack: 0.0003 352296 1. {main}()
/campus/campus.php:0 0.0125 1654360 2. max() /campus/campus.php:39
Here is the code I’m using:
$sql= "SELECT MIN(capacity), MAX(capacity) FROM room";
$res =& $db->query($sql);
if (PEAR::isError($res)) {
die($res->getMessage());
}
while($row = $res->fetchRow())
{
$minCapacity = $row[MIN(capacity)];
$maxCapacity = $row[MAX(capacity)];
}
echo $minCapacity;
echo $maxCapacity;
the indicated quotes are missing.
min()is a valid PHP function, so you’re trying to use the results of PHP’s min function as an array index in $row.