vhdz04 vhdz04 - 2 years ago 222
PHP Question

Retrieve a value from sqli_query

I am trying to retrieve the highest userID in my sql table. I am using sqli_query function in PHP. I know this function returns an object. How can I assign the returned userID to a variable?

$query = "SELECT max(UserID) FROM userinfo";
$highID = mysqli_query($conn, $query);

if (!$highID) {
printf("Error: %s\n", mysqli_error($conn));

while($rows = mysqli_fetch_array($highID, MYSQL_ASSOC))

echo "{$rows['UserID']}";

this is the error I get

Notice: Undefined index: UserID in C:\Apache24\htdocs\dbpractice\info.php on line 165

Answer Source
$query = "SELECT max(UserID) as maxUserID FROM userinfo";

Now you can use

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download