Serial Number with MySQL Query Result using PHP - Web Development and Web Design Codes

Latest

Tuesday, March 13, 2018

Serial Number with MySQL Query Result using PHP

Serial Number with MySQL Query Result using PHP

Hi Friends in this lesson we will learn how to display MySQL data with serial number..just follow the below codes to serial MySQL query and display as html table..
Serial Number with MySQL Query Result using PHP
Serial Number with MySQL Query Result using PHP
Database name: codenair
Table Name: user

SQL Structure for Table 'user'
CREATE TABLE IF NOT EXISTS `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

-- Dumping data for table `users`
INSERT INTO `users` (`id`, `username`, `email`) VALUES
(NULL, 'Codenair', 'Anjan@yahoo.com'),
(NULL, 'abcd', 'Anjankumar@gmail.com'),
(NULL, 'codeigniter', 'mymail@mail.com'),
(NULL, 'ANJAN', 'biswasshiuli608@gmail.com');

Files:
index.php
<html>
<head>
<title>Serial Number with MySQL Query Result using PHP</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<h2>Serial Number with MySQL Query Result using PHP</h2>
<table>
  <tr>
    <th>Serial No:</th>
 <th>UserName</th>
 <th>Email</th>
  </tr>
  <?php
  $conn=new mysqli('localhost','root','','codenair.com');
  $sql=mysqli_query($conn,"SELECT*FROM user");
  $counter=1;
  while($row=mysqli_fetch_object($sql)){
   ?>
  <tr>
     <td><?php echo $counter++;?></td>
  <td><?php echo $row->username;?></td>
  <td><?php echo $row->email;?></td>
  </tr>
  <?php
  }?>
</table>
</html>

To style index page add below css codes
style.css
 input[type=text]{
  padding:4px;
  border-radius:4px;
   width:250px;
 }
 input[type=submit]{
  padding:5px;
  border-radius:4px;
  background:black;
        
  color:white;
  cursor:pointer;
 }
 table {
    border-collapse: collapse;
    width: 35%;
font-family:verdana;
}

th, td {

    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
    background-color: #4CAF50;
    color: white;
}

That's it Friends how to Serial Mysql Query using PHP..
if you like please share and don't forget to comments..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.