MySQL Question

Selecting Data from SQL Database Returns "1"

This is my first SQL Database. I've been able to successfully connect to my server and database. But, when I use a query to select data from one of the columns in my table, it returns the number "1". Why is this?


$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());

$sql = "SELECT Item FROM Items";
$result = $conn->query($sql);

echo "<h1>Connected successfully<h1>";
echo "<p class='lead'>" + $result + "</p>";



Here's an image of the table named

enter image description here

This is what shows up on the webpage where it should
the contents in the

enter image description here

Answer Source

You're just echoing the whole object, not individual rows. You need to do something like this to iterate over each row.

if ($result = $conn->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        echo "<p class='lead'>" . $row[0] . "</p>";

    /* free result set */
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download