How to read all record from MySQL table and display the fields using MySQLi in PHP

1 Answer

0 votes
$db_host        = 'localhost';
$db_user        = 'root';
$db_password    = '';
$db_name        = 'allonpage';

$con = new mysqli("localhost", $db_user, $db_password , $db_name);

if (mysqli_connect_errno()) 
    die("Connection Error: " . mysqli_connect_error() . "<br />");

if ($result = $con->query("SELECT * FROM images")) 
{
    while($row = $result->fetch_array())
    {
        echo $row['href'] . " - " . $row['src'] . "<br />";;
    }
    $result->close();
}
else
    echo "Query Error: " . mysqli_error($con);

$con->close();


/*
run: 

https://www.ws.com - http://www.ws.com/images/us-flag.gif
https://www.ws.com - http://www.ws.com/images/logo.png
https://www.ws.com - http://www.ws.com/images/tools.png
...

*/

 



answered Jul 6, 2016 by avibootz

Related questions

2 answers 267 views
1 answer 195 views
2 answers 189 views
1 answer 199 views
...