phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP MySQL: Display Data

Tag: mysql, database, search, data   Category: PHP Database
post: 02 Mar 2008 read: 2,804


php mysql basic step by step tutorial - part 10: In looking for one or more data in the database, you can use syntax such as:
SELECT field1,field2,... FROM name_table WHERE condition1,condition2,...
ORDER BY name_field

If field displayed is all field from the table, so all of the name field itself does not have to be declared but it is enough to change with the sign * then all field will be accessed. ORDER BY parameter shows the data that is organized based on which field you choose. The default sequence is from the smallest one (number sequence), from A-Z (letter sequence), and from the first data to the last data (time sequence). You can reverse these sequence by adding DESC attribute. For example, we will search all of the database data of data_employees and show it based on the name field.


<html>
<head>
<title>Search data</title>
</head>
<body>
<table>
  <tr>
    <td align="center">EMPLOYEES DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <tr>
        <td>NAME</td>
        <td>EMPLOYEES<br>NUMBER</td>
        <td>ADDRESS</td>
      </tr>
<?
//the example of searching data 
with the sequence based on the field name
//search.php
mysql_connect("localhost","root","admin");//database connection
mysql_select_db("employees");
				
$order = "SELECT * FROM data_employees ORDER BY name";
//order to search data
//declare in the order variable
				
$result = mysql_query($order);	
//order executes the result is saved
//in the variable of $result
				
while($data = mysql_fetch_row($result)){
  echo("<tr><td>$data[1]</td><td>$data[0]</td><td>$data[2]</td></tr>");
}
?>
    </table>
  </td>
</tr>
</table>
</body>
</html>

The result:

php mysql display data

Then, you can use DESC like
$order = "SELECT * FROM data_employees ORDER BY name DESC"
so the result will be:

php mysql display data


Series this article:
PHP MySQL: Connecting to Database Use mysql_connect()
PHP MySQL: Making Database Use mysql_create_db()
PHP MySQL: Making Table
PHP MySQL: The Data Type of Field
PHP MySQL: Char and Varchar Data Type
PHP MySQL: Data Type of Date
PHP MySQL: MySQL Syntax Orders
PHP MySQL: Inserting Data
PHP MySQL: Creating Form Insert Data
PHP MySQL: Display Data
PHP MySQL: mysql_fetch_row() Function
PHP MySQL: mysql_fetch_array() Function
PHP MySQL: Editing data
PHP MySQL: Deleting data
PHP MySQL: Adding Field Table
PHP MySQL: Editing Field Table
PHP MySQL: Deleting Field Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting