Display Limited Query from Database in php - Web Development and Web Design Codes

Latest

Tuesday, February 13, 2018

Display Limited Query from Database in php

Display Limited Query from Database in php

Display Limited Query from Database in php
Display Limited Query from Database in php

Hi Friends Today we are going to learn how to display limited rows from database using php..

=>Database and Table:
  Database Name: test
 Table name: user

Table Structure for table user:

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

Dumping Data for Table User:

INSERT INTO `user` (`id`, `username`, `email`) VALUES
(NULL, 'ANJAN KUMAR', 'Anjankumardhali@gmail.com'),
(NULL, 'Supriya Gain', 'SupriyaStar@Yahoo.com'),
(NULL, 'Supriya Gain', 'SupriyaStar@Yahoo.com'),
(NULL, 'ANJAN', 'biswasshiuli608@gmail.com'),
(NULL, 'ANJAN', 'biswasshiuli608@gmail.com'),
(NULL, 'ANJAN', 'biswasshiuli608@gmail.com'),
(NULL, 'Supriya Gain', 'SupriyaStar@Yahoo.com'),
(NULL, 'ANJAN KUMAR', 'Anjankumardhali@gmail.com'),
(NULL, 'ANJAN', 'biswasshiuli608@gmail.com'),
(NULL, 'ANJANBD', 'biswasshiuli608@gmail.com');

Create 2 files named 
1. index.php
2. style.css

1. index.php

<html>
<head>
<title>Display Limited Post or rows in PHP MySQL</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<h2>Displaying Limited ROWS/Records php mysql</h2>
<p>5 Records per Page</p>
<table>
  <tr>
    <th>ID No:</th>
 <th>Name:</th>
 <th>Email:</th>
  </tr>
  <?php
  $conn=new mysqli('localhost','root','','test');
  //We will show 5 ROWS per page
  $limit=5;
  $result=mysqli_query($conn,"SELECT*FROM user limit $limit");
  while($row=$result->fetch_array()){
  ?>
  <tr>
    <td><?php echo $row['id'];?></td>
 <td><?php echo $row['username'];?></td>
 <td><?php echo $row['email'];?></td>
  </tr>
  <?php }?>
</table>
</html>

2. style.css

td,th{
 padding:8px;
 border:1px solid green;
}
table{
 border-collapse:collapse;
 width:40%;
}
th{
 font-size:16px;
 padding:10px;
 color:white;
 background:#0033cc;
 border-radius:4px;
}
tr:nth-child(odd){background:lightgreen}
tr:nth-child(even){background:lightblue}

That's it Friend How to display limited rows from MySQL database.. Thank You...

No comments:

Post a Comment

Thank You for Your Comment

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