fetch data from database using php/mysqli select query

fetch data from mysql table and print using php. Here data are displayed in tabular format (multiple column), but it can be changed to noraml display.  Let us see, how mysql select query retrieve and print data via php.

Very simple php code. Change the DB name and password. Connection details can also be made in different php.

<?php

$DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100'
$DBUser   = 'root';
$DBPass   = '';
$DBName   = '';

$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName);

if ($mysqli->connect_error) {
  trigger_error('Database connection failed: '  . $mysqli->connect_error, E_USER_ERROR);
}
else
{
          $query1 =$mysqli->query("select name from posuser");
              echo "<table border=1>";           
          while($result = $query1->fetch_array())
        {  
           echo "<tr><td>$result[name]</td></tr>";
        }
           echo "</table>";
         echo "<br>Read next tutorial to insert, update values using php/mysqli<br><br>";
         echo "<a href='http://techietet.com/howto'>Techietet.com</a>";
        
}
?>

 

While loop is used to fetch multiple rows. Here a data are displayed in table structure by using html table tag in php.

How to display data fetched from mysql without tabular column.