Henry
Henry

Reputation: 311

Reading from a database with PHP

I'm trying to pull some information from a database, and the connection is working, but for some reason it isn't recognizing my query, even though I confirmed the query in the database with SQL and had it "generate PHP code". The echo statement is coming up blank. It's a mySQL database. Thanks for your help.

$query = "SELECT `contact` FROM `contactinfo` WHERE member=\'Henry\'";
$contact = mysqli_query($db,$query);
echo $contact;

Upvotes: 3

Views: 89

Answers (1)

GoodSp33d
GoodSp33d

Reputation: 6282

$contact contains MySQL result object you need to fetch data from this to use this in your application.

$query   = "SELECT `contact` FROM `contactinfo` WHERE member = 'Henry'";
$contact = mysqli_query($db, $query);
while ($row = mysqli_fetch_row($contact)) {
  echo $row[0]; // 0 to n indicates the Column(s) Selected in SELECT Query
}

Upvotes: 3

Related Questions