banner



How To Display Data From Database In Html

To fetch and display data from MySQL database in php; i will completely guide yous from scratch for how to fetch/retrieve data from mysql database in php and brandish in bootstrap html table.

Also, I will latest bootstrap table to display fetched data from MySQL database with PHP.

Note that – You must take installed XAMPP server on your window, ubuntu or Mac automobile. Equally well every bit whatever text editor installed, which can exist used to write code in your php files.

PHP Code to Retrieve/Fetch Data From MySQL Database and Display in HTML Table

Use the following steps for fetch/think data from database in php and display in html table:

  • Pace one – Start Apache Spider web Server
  • Pace 2 – Create PHP Projection
  • Step 3 – Execute SQL query to Create Table
  • Footstep 4 – Create phpmyadmin MySQL Database Connection File
  • Step 5 – Create Fetch Data PHP File From Database
  • Step 6 – Create Html Tabular array To Display Retrieve Data From MySQL DB
  • Pace 7 – Open Browser And Examination This Projection

Footstep 1 – Start Apache Web Server

At present, you need to start your apache web server. And as well as start Apache and mysql web server. Yous can see in the paradigm beneath how to start apache and mysql server:

Step two – Create PHP Project

In stride 2, navigate to your xampp/htdocs/ directory. And within xampp/htdocs/ directory, create one folder. And you can proper noun this folder anything.

Here, I volition "demo" the name of this folder. And so open up this binder in any text editor (i will use sublime text editor).

Pace 3 – Execute SQL query to Create Table

In footstep 3, open up your browser and type http://localhost/phpmyadmin. Then create database and tabular array by running the following sql query:

CREATE DATABASE my_db;   CREATE Table `customers` ( `custId` INT(eleven) NOT NULL AUTO_INCREMENT, `fname` VARCHAR(255) Cipher DEFAULT Nil, `lname` VARCHAR(255) NULL DEFAULT Nix, `email` VARCHAR(255) Zero DEFAULT Goose egg, `created` DATETIME Naught DEFAULT Nil, Master Central (`custId`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB AUTO_INCREMENT=1;  INSERT INTO `customers` (`custId`, `fname`, `lname`, `email`, `created`) VALUES (NULL, 'Tiago', 'Sam', '[email protected]', Cypher), (Zero, 'Anil', 'Kumar', '[e-mail protected]', Cipher);          

Step iv – Create phpmyadmin MySQL Database Connection File

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

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

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

Pace 5 – Create Fetch Data PHP File From Database

In step 5, yous need to create a php file that named remember-information.php. Which is used to retrieve or fetch information from MySQL database table.

Then add the following code on retrieve-data.php file:

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

Footstep vi – Create Html Table To Display Retrieve Data From MySQL DB

In step 6, you lot need create a php file that named alphabetize.php. Which is used to fetch all the information from the MySQL database table.

Annotation that, you need to include remember-information.php file on index.php file. Don't worry i have already include this file on index.php file.

So, y'all tin add this code in your alphabetize.php file:

<!DOCTYPE html> <html lang="en"> <caput>     <meta charset="UTF-8">     <title>PHP Code to Retrieve Data from MySQL Database and Display in html Table</title>     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/four.5.ii/css/bootstrap.min.css"> </head> <torso>  <div class="container mt-ii">     <div grade="row">         <div grade="col-md-12">             <div class="page-header">                 <h2>Fetch Information From Database in PHP and Display in HTML Table</h2>             </div>              <tabular array class="table">               <thead>                 <tr>                   <th telescopic="col">#</th>                   <th scope="col">First</th>                   <th scope="col">Last</th>                   <th telescopic="col">Email</th>                 </tr>               </thead>               <tbody>                 <?php include 'call up-data.php'; ?>                  <?php if ($effect->num_rows > 0): ?>                  <?php while($array=mysqli_fetch_row($consequence)): ?>                  <tr>                     <th scope="row"><?php echo $array[0];?></th>                     <td><?php echo $array[ane];?></td>                     <td><?php repeat $array[2];?></td>                     <td><?php echo $array[3];?></td>                 </tr>                  <?php endwhile; ?>                  <?php else: ?>                 <tr>                    <td colspan="3" rowspan="1" headers="">No Information Found</td>                 </tr>                 <?php endif; ?>                  <?php mysqli_free_result($upshot); ?>                </tbody>             </table>         </div>     </div>         </div>  </torso> </html>

Step vii – Open Browser And Test This Project

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

This project will be looks like shown in below image:

how to retrieve data from database in php and display in html table

Thanks for reading this post.

Recommended PHP Tutorials

How To Display Data From Database In Html,

Source: https://laratutorials.com/how-to-fetch-data-from-database-in-php-and-display-in-html-table/

Posted by: moodybeftedind1982.blogspot.com

0 Response to "How To Display Data From Database In Html"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel