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 fetch data from table by using php

Answer: MySQL fetch array to use for Select data from MySQL Data Table. Create the MySQL query for fetching data from a table and then execute it with mysql_query() function. We can fetch data from a table of the database by using MYSQL SELECT statement.

There are many functions in PHP for fetching data but the most commonly used function is mysql_fetch_array() function.

How to Fetch data from MySQL Database using PHP?

1) SELECT * FROM table_name

or

2) SELECT column_name1, column_name2 FROM table_name




Example of Fetching Data 

<?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';
}
 $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)) {
?>
        <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
}
?>
     </table>
  </body>
</html>


This code produces the following result:

Output:

S NoStudent NameAddressEnrollment NoJoining Date
1JohnCalifornia1010/02/2017
2JakobNew York2020/05/2017

Learn more about PHP




Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic