April 3, 2016
How to Display records from a MySQLi Database with PHP

Hi, friends in this tutorial we going to see how to display records from a MySQLi database with PHP. Data can be fetched from MySQL tables via this we executing SQL SELECT statement mysql_query function in PHP. We have more options to fetch data from MySQL. The common frequently used option is to use function mysql_fetch_array(). In this function returns row as an associative array, a numeric array, or the two.
display.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php $server = "localhost"; $user = "root"; $pass = ""; $dbname = "info"; // Create connection in mysqli $connection = new mysqli($server, $user, $pass, $dbname); //Check connection in mysqli if($connection->connect_error){ die("Error on connection:" .$connection->connect_error); } //Display the informaion $sql = "SELECT * FROM infom"; $res = $connection->query($sql); if($res->num_rows > 0){ while($row = $res->fetch_assoc()){ echo "ID". $row["id"]. "<br/>"; echo "Name". $row["name"]. "<br/>"; echo "Last Name". $row["lname"]. "<br/>"; echo "Age". $row["age"]. "<br/>"; } } else { echo "No Record Found!"; } $connection->close(); ?> |
Download
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]