I try to run the code below from my website and I get this. I can insert records to the same database and table with no problem. I just want to read and display the records in the table.
- { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. " "; } } else { echo "0 results"; } mysqli_close($conn); ?>
<?php
$servername = "Some serveron.ipagemysql.com";
$username = "Anyname";
$password = "xxxx";
$dbname = "Anything";
$table = "user";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, first_name, last_name FROM $table";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>