Reputation: 23
I've a problem with get a single value from mysql and variable assignment.
var_dump($val)
looks ok:
object(stdClass)#5 (1) { ["min(ID_plants)"]=> string(1) "1" }
And i need this "1" assign to variable.
$first= "SELECT min(ID_plants) from Plants";
if (mysqli_query($link,$first)){
$res = mysqli_query($link,$first);
$val = mysqli_fetch_object($res);
}
//var_dump($val);
//$first_index$=($val->MIN(ID_plants));
Upvotes: 0
Views: 33
Reputation: 6388
You should use prepared statement
instead of mysqli
.
Change your query to
SELECT min(ID_plants) As minPlants from Plants // Alias
After $val = mysqli_fetch_object($res);
you can get the value by using $val->minPlants
Upvotes: 0
Reputation: 133400
you should use an alias for min(ID_plants)
$first= "SELECT min(ID_plants) my_min_id from Plants";
if (mysqli_query($link,$first)){
$res = mysqli_query($link,$first);
$val = mysqli_fetch_object($res);
}
//var_dump($val);
$first_index$=($val->my_min_id);
Upvotes: 2