0

I just started PHP and was wondering how you would echo a single value result from a database query.

Here's an example of what I'm trying to do:

$query = "SELECT `userID` FROM `users` WHERE username='bill'";
$result = $mysqli->query($query);

echo $result;

I figured out that $result contains an mysqli object based on the errors I was receiving, but can't get it to actually print out, say, "10001."

cid
  • 11
  • 1
  • 2

1 Answers1

0

This is how you can do it

$query = "SELECT `userID` FROM `users` WHERE username='bill'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
echo $row["userID"];

http://in2.php.net/mysqli_fetch_assoc

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63