banner



How To Fetch Data From Database In Php Using Mysqli

How to fetch unmarried row data from database and brandish on html page in php postal service, i will teach you lot stride by step on how to fetch/remember single row data from mysql database in php and brandish in html page.

Likewise, I will latest bootstrap 4 library to display fetched data from MySQL database with PHP on html. Too as i will employ easy mysqli function (mysqli_query(), mysqli_connect(), mysqli_fetch_row()) to retrieve single row data from MySQL DB and display it on HTML web page.

Notation that – You must have installed XAMPP server on your window, ubuntu or Mac machine. As well as any text editor installed, which can be used to write code in your php files.

Fetch Single Row Information/Record From Database in PHP MySQL

Follow below given unproblematic steps for fetch unmarried row information from database in php mysqli and display on html spider web page table:

  • Footstep i – Create PHP Project
  • Step two – Execute SQL query to Create Table
  • Pace three – Create phpmyadmin MySQL Database Connexion File
  • Pace 4 – Fetch Single Row From Database in PHP
  • Step 5 – Create Html Folio To Display Fetched Information From MySQL DB
  • Pace half dozen – Open Browser And Test This Project

Step 1 – Create PHP Project

In step 1, navigate to local web server directory. And inside directory, create one folder. And you tin can name this folder anything.

For example, i will use xampp server so, i willl navigate to C/xampp/htdocs/.

Here, I volition "demo" the proper name of this binder. Then open this folder in any text editor (i will apply sublime text editor).

Step 2 – Execute SQL query to Create Table

In stride 2, open your browser and type http://localhost/phpmyadmin. Then create database and tabular array past running the following sql query:

CREATE DATABASE my_db;   CREATE Table `customers` ( `custId` INT(11) NOT NULL AUTO_INCREMENT, `fname` VARCHAR(255) Zero DEFAULT Nix, `lname` VARCHAR(255) Aught DEFAULT NULL, `email` VARCHAR(255) Nil DEFAULT Cipher, `created` DATETIME Null DEFAULT Zero, Master KEY (`custId`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB AUTO_INCREMENT=ane;  INSERT INTO `customers` (`custId`, `fname`, `lname`, `email`, `created`) VALUES (NULL, 'Tiago', 'Sam', '[email protected]', Zip), (NULL, 'Anil', 'Kumar', '[electronic mail protected]', Nil);          

Pace 3 – Create phpmyadmin MySQL Database Connection File

In step three, create a php file that named mydbCon.php. Which is used to connect phpmyadmin mysql database to project (demo).

So, now create mydbCon.php file and add together the below given code into your file:

<?php      $hName='localhost'; // host name      $uName='root';   // database user name      $password='';   // database password      $dbName = "my_db"; // database proper noun      $dbCon = mysqli_connect($hName,$uName,$password,"$dbName");        if(!$dbCon){           die('Could non Connect MySql Server:' .mysql_error());       } ?>

Stride 4 – Fetch Unmarried Row From Database in PHP

In footstep 4, you need to create a php file that named fetch-single-row-data.php. Which is used to fetch single row data from MySQL database table in PHP.

Then add the following code on fetch-single-row-data.php file:

<?php   include 'mydbCon.php';  $query="select * from customers limit 1"; // Fetch all the data from the table customers  $issue=mysqli_query($dbCon,$query);  $singleRow = mysqli_fetch_row($result);  ?>

Step 5 – Create Html Page To Display Fetched Data From MySQL DB

In footstep v, you need create a php file that named index.php. Which is used to display unmarried row information from the MySQL database table.

Note that, y'all demand to include fetch-single-row-data.php file on index.php file. Don't worry i accept already include this file on index.php file. Because this fetch-unmarried-row-data.php file code will fetch single row data from database table.

So, you lot tin can add together this code in your index.php file:

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>How to Fetch Single Row Information From Database in PHP</title>     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> </head> <body>  <div class="container mt-2">     <div form="row">         <div grade="col-doc-12">             <?php include 'fetch-single-row-data.php'; ?>             <div course="bill of fare">               <div class="card-header">                 Fetch Single Row Data From Database in PHP and Display in HTML Page               </div>               <div grade="carte du jour-body">                 <b>First Name</b> :- <span class="bill of fare-text"><?php repeat $singleRow['1']; ?> </span><br>                 <b>Last Name</b> :- <span class="menu-text"><?php echo $singleRow['1']; ?> </span><br>                 <b>E-mail Name</b> :- <span grade="card-text"> <?php echo $singleRow['one']; ?></span><br>               </div>             </div>         </div>     </div>         </div>  </body> </html>

Stride six – Open Browser And Examination This Project

Finally, you lot need to open up your browser and type http://localhost/demo this run projection on local machine.

How to fetch and display unmarried row data in php using mysqli volition be looks like shown in below paradigm:

fetch single row data from database in php and display in html page

Recommended PHP Tutorials

Thanks for reading this post.

How To Fetch Data From Database In Php Using Mysqli,

Source: https://laratutorials.com/how-to-fetch-single-row-data-from-database-in-php/

Posted by: baumancapils88.blogspot.com

0 Response to "How To Fetch Data From Database In Php Using Mysqli"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel