Adam Kona Adam Kona - 2 months ago 7
MySQL Question

How do I output the result from an sql query onto the screen in php

The following is the code I use to try and achieve this.

$con=mysqli_connect("localhost:8889","root","root","booksmart_properties");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else{

echo "we connected";
}

// Perform queries
$sql=mysqli_query($con,"SELECT * FROM ListedProperties");
$result=mysqli_fetch_assoc($sql);



echo $result['*'];


mysqli_close($con);

?>




I'm new to php and i'm sure it's something small, I just can't see it.

Answer

Use PHP foreach loop like this:

foreach($result as $key => $val)
{
     print $val;
}