0

I'm trying to display the results of a database on a webpage. Using this example, I have come up with this piece of php code below:

<?php

    $con=mysqli_connect("217.199.187.70","cl52-domains","######","cl52-domains");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $results = mysqli_query($con, "SELECT * FROM domains");

    echo "<table border='1'>
    <tr>
    <th>ID</th>
    <th>Domain</th>
    <th>Address</th>
    <th>Price</th>
    </tr>";

    while($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['domain_name'] . "</td>";
    echo "<td>" . $row['domain_address'] . "</td>";
    echo "<td>" . $row['price'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    mysqli_close($con);
    ?>

However, when I refresh my webpage, it shows the table header (no errors), but 0 results. Here is my table specifications:

enter image description here enter image description here

Can someone tell me why I'm not getting any results?

Community
  • 1
  • 1
ben_dchost
  • 875
  • 4
  • 13
  • 24
  • You assign to `$results`, you read from `$result` (no `s`). Is that in the real code or a copying error? You should enable warnings when developing, then you'll see the notice about the undefined variable. – Barmar Oct 23 '14 at 11:06

1 Answers1

0

Change

while($row = mysqli_fetch_array($result))

To

while($row = mysqli_fetch_array($results))

You probably made a typo in referencing the $results variable.

Allmighty
  • 1,499
  • 12
  • 19
  • Thank you! It works! Yes silly error on my side, I thought it was a SQL issue (hence screenshots of tables), but should have guessed it was a reference typo... – ben_dchost Oct 23 '14 at 11:15