Reputation: 305
I have
var_dump($row[Price]);
which prints out all prices from my query ($query = "Select * FROM myTable WHERE...")
like this:
string(5) "37.00" string(5) "20.00" string(5) "23.00" string(5) "12.00" string(5) "10.00"
Now: I would like to print (echo) out just the Lowest Value which is "10.00" in this case.
How do I do this?
Upvotes: 0
Views: 72
Reputation: 10717
while ($row = mysql_fetch_array($result))
{
// Print out the contents of each row into a table
}
Instead of above codes, use following:
$list = mysql_fetch_array($result);
function _getPrice($array) {
return $array['Price'];
}
$prices = array_map('_getPrice', $list);
echo min($prices);
Or you can get MIN with SQL Query like @Teneff said:
SELECT MIN(price) FROM myTable WHERE...
Upvotes: 2
Reputation: 153
You will have to iterate over all strings, convert them to integers and than iterate again to find lowest value. It would be better to use some sort criterion with SQL query and then take first value.
Upvotes: 0
Reputation:
You could add ORDER BY to your query, ORDER BY prices ASC. Then print the first element of the array
Upvotes: 0