SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

PHP MySQL data display from a table

Displaying data from a table is a very common requirement and we can do this in various ways depending on the way it is required. We will start with a simple one to just display the records and then we will move to advance one like breaking the returned records to number of pages. We will start with simple displaying the records of this table.
id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
7 My John Rob Fifth 78

Before starting please ensure that you have connected to MySql database and also check the article on PHP MySQL query to know how to execute MySql queries by using PHP

Let us first start by storing the query in a variable and then executing it
Related Tutorial
PHP MySQL Functions
PHP MySQL Query


$query="select * from student";  // query string stored in a variable
$rt=mysql_query($query);          // query executed 
echo mysql_error();                    // if any error is there that will be printed to the screen

We will use mysql_fetch_array function to get the array of records and then we will loop through it to display record by record. You can see our php array to lean how to use array in PHP.  The code below will print name , class and mark records and you can see we have used <br> tag to give one line break after each record. This can be formatted well to display inside a table. 

while($nt=mysql_fetch_array($rt)){
echo "$nt[name] $nt[class] $nt[mark]<br>";     // name class and mark will be printed with one line break at the end
}

Discuss this tutorial at forum


Further readings
PHP MySql Query
PHP MySql Data Display
Displaying records without repetitions of same field data
PHP Paging or breaking records per page
PHP MySQL Connection
Checking MySQL by phpinfo

 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.