VIEW Query is MySql using PHP ?


After creating a table with required fields in a database we need to insert information into it, after that we need to view the information so that we can check whether the information in the database is inserted or not.

There are two ways to view data from the database table:-
  • View all the data from the database table.
  • View particular data from the database.
View all the data from the database table.

we need to create a page for viewing all the values from the table.(View.php)
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>View data</title>
 </head>
 <body>
 <?php
 $servername="localhost";
 $username="root";
 $password="";
 $db="project";     */suppose project is our database name */
 $conn=mysqli_connect($servername,$username,$password,$db);
 if(!$conn)
 {
 echo"not connected";
 }
 $q="SELECT * FROM `table1`";  */ suppose table1 is our table name  */
 $qu=mysqli_query($conn,$q);
 ?>
 <table align="center" border="2"> 
 <tr>
 <th>name</th>
 <th>roll</th>
 <th>email</th>
 <th>password</th>
 </tr>
 <?php
 while($rs=mysqli_fetch_assoc($qu))
 {
 ?>
 <tr>
 <td><?php echo $rs ['name'];?></td>
 <td><?php echo $rs ['roll'];?></td>
 <td><?php echo $rs ['email'];?></td>
 <td><?php echo $rs ['password'];?></td>
 </tr>
 <?php
 }
 ?>
 </body>
 </html>

To view particular information from the database.

We need to create a page for inserting the information from user (to view the required information of that field(View1.php)
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>View data for</title>
 </head>
 <body>
 <form name="f" method="POST"  action="view_action.php">
 Enter roll<input type="text" name="t1">
 <input type="submit">
 lt;/body>
 </html>

connectivity page to view information(view_action.php)
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>View only</title>
 </head>
 <body>
 <?php
  $servername="localhost";
  $username="root";
  $password="";
  $db="project";    */ suppose project is our database name. */
  $conn=mysqli_connect($servername,$username,$password,$db);
  if(!$conn)
     {
         echo "not connected";
     }
  $r=$_REQUEST['t1'];
  $q="SELECT * FROM `table1` WHERE roll=$r"; */ Suppose table1 is our table name. */
  $qu=mysqli_query($conn,$q);
  $rs=mysqli_fetch_assoc($qu);
 ?>
 <table align="center" border="2">
 <tr>
 <th> Name </th>
 <th> email </th>
 <th> password </th>
 </tr>
 <tr>
 <td> <?php echo $rs['name'];?></td>
 <td> <?php echo $rs['email'];?></td>
 <td> <?php echo $rs['password'];?></td>
 </tr>
 </table>
 </body>
 </html>