saftutorials.com

HTML

How to download HTMl Editors

How to use HTML tags

How to Comment in HTML

How to create an HTML link

How to link to a specific part of a page HTML

How to Insert Images with HTML

How to insert audio in HTML

How to insert videos in HTML

How to use Table Tag in HTML

How to Use HTML List Elements

How to use HTML Iframe

How to use HTML Symbols

How to use HTML Color Codes

How to Create HTML From

How to learn HTML

CSS

How to use CSS Background

JS

PHP

How to redirect to another page using PHP

How to get last inserted id in MySQL using PHP

How to learn php

How to insert a row into database by using PHP

How to fetch data from table by using php

How to print table data by using while loop in php

How to perform search operation into database by using php

MySQL

How to create Table in PHP MySQL?

How to Insert Data Into MySQL Database Table Using PHP?

How to Select Data from MySQL Database Tables Using PHP

How to Update data in MySQL Database Table using PHP

How to Delete Data from MySQL using PHP

How to make MySQL query ORDER BY conditions

How to Select LIMIT data in PHP MySQL

SQL

BOOTSTRAP

AJAX

DATATABLE

SEO

EARNING

GOOGLE

FACEBOOK

YOUTUBE

WordPress

How to Install WordPress?

How to use WordPress Dashboard?

How to Install Plugins in WordPress?

How to Customize WordPress Plugins?

How to Change General Settings in WordPress?

How to Change Writing Settings in WordPress

How to Setup the Reading Settings in WordPress

How to Setup the Discussion Settings in WordPress

How to Setup the Media Settings in WordPress

How to Setup the Permalink Settings in WordPress

How to Setup the Plugin Settings in WordPress

How to Add Categories to WordPress

How to Edit Category in WordPress

How to Delete Category in WordPress

How to Arrange Category in WordPress

How to Add a new Post in WordPress

How to Edit Post in WordPress

How to Delete Post in WordPress

How to Review Post in WordPress

How to add Media in WordPress

How to Edit Media in WordPress

How to add a Page in WordPress

How to Delete Media in WordPress

How to Add Page in WordPress

How to Edit Pages in WordPress

How to Learn WordPress

How to Delete Page in WordPress

How to add New Tag in WordPress

How to Edit Tags in WordPress

How to Delete Tags in WordPress

How to print table data by using while loop in php

Answer: There are many types loop in PHP. And While Loop is most used for print data from MySQL. You can print all or some filtered data from MySQL Data Table using While loop


Example of How to print table data by using while loop in PHP

<?php
 $database_host = 'localhost:3036';
 $database_user = 'root';
 $database_pass = '';
 $conn = mysql_connect($database_host, $database_user, $database_pass);
 if(! $conn ) {
   die('Could not connect: ' . mysql_error());
 }else{
   echo 'Connected successfully\n';
}
 $selected_or_not = mysql_select_db( 'xyz_school' );
 if(! $selected_or_not ) {
   die('Not Selected xyz_school database');
 }else{
   echo 'Selected xyz_school database';
}

  $q = htmlspecialchars($_POST["q"], ENT_QUOTES, "UTF-8");
  $q = stripslashes($q);

  $sql = " SELECT * FROM student " ; 
  $result = mysql_query( $sql, $conn );
  if(! $result ) {
  die('Could not get data: ' . mysql_error());
}
 mysql_close($conn);
?>


<!DOCTYPE html>
<html>
<body>
    <h2>Student List</h2>
     <table>
        <th>
           <td>S No</td>
           <td>Student Name</td>
           <td>Address</td>
           <td>Enrollment No</td>
           <td>Joining date</td>
        </th>
	<?php
	$i = 1;
	while($row = mysql_fetch_array($result)) { // Start While
	?>
        <tr>
           <td><?php echo $i++;?> </td>
           <td><?php echo $row['student_name'] ."or". $row[1]; ?> </td> // Note: You can use declare data by using Column name or Column number, First column number start from 0.
           <td><?php echo $row['student_address'] ."or". $row[2]; ?> </td>
           <td><?php echo $row['student_enrollment_no'] ."or". $row[3]; ?> </td>
           <td><?php echo $row['join_date'] ."or". $row[4]; ?> </td>
        </tr>
	<?php
	} // End While
	?>
     </table>
  </body>
</html>

If you use this code then you can print all your data from student table or your query table.


Learn more about PHP




Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic