Fetch Data from Mysql using Php


Retrieving data with php & mysql

Normally the vast majority of the work finished with MySQL includes pulling down information from a MySQL database. In MySQL, information is recovered with the "SELECT" watchword. Consider SELECT working an indistinguishable path from it does on your PC. In the event that you needed to duplicate some data in a record, you would first choose the coveted data, at that point reorder.

using mysql select & from

PHP & MySQL Code:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM example")
or die(mysql_error());  

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

echo "Name: ".$row['name'];
echo " Age: ".$row['age'];

?>

Display:

Name: Tim Mellowman Age: 23

'$result = mysql_query("select * from example")'
When you play out a SELECT question on the database it will restore a MySQL Resource that holds everything from your MySQL table, "illustration". We need to utilize this Resource in our PHP code, so we have to store it in a variable, $result.

'select * from example'
Indeed, this is a halfway rehash of a similar line of code, yet we needed to clarify this MySQL proclamation in more prominent detail once more! 

In English, this line of code peruses "Select each passage from the table case". The reference bullet is the trump card in MySQL which just advises MySQL to incorporate each and every section for that table.

'$row = mysql_fetch_array( $result );'
$result is currently a MySQL Resource containing information from your MySQL table, "case". Information is being put away in $result, yet it isn't yet unmistakable to guests of your site. When we pass $result into the mysql_fetch_array work - mysql_fetch_array($result) - an acquainted cluster (name, age) is returned. 

In our MySQL table "case," there are just two fields that we think about: name and age. These names are the keys to extricating the information from our cooperative exhibit. To get the name we utilize $row['name'] and to get the age we utilize $row['age'].

Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment