Leakbali
w3 Tutorial, Web Tutorial
Register   Login
Share

Getting a Row of Data using mysql_fetch_array 


mysql_fetch_array returns the first row in a MySQL Resource in the form of an associative array. The columns of the MySQL Result can be accessed by using the column names of the table. In our table example these are: name and age. Here is the code to print out the first MySQL Result row.

Getting a Row of Data using mysql_fetch_array PHP and MySQL Example

<?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 
	 
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['name']. " - ". $row['age'];
?>

Getting a Row of Data PHP & MySQL Display

Putu Sanjaya - 20
This is just what we expected would happen! Now, the cool thing about mysql_fetch_array is that you can use it again on the same MySQL Resource to return the second, third, fourth and so on rows. You can keep doing this until the MySQL Resource has reached the end (which would be three times in our example).

Sounds like an awfully repetitive task. It would be nice if we could get all our results from a MySQL Resource in an easy to do script.
More Tutorial
  1. MYSQL - MySQL Fetch Array
  2. MYSQL - A Row of Data
  3. MYSQL - Getting a Row of Data using mysql_fetch_array
  4. MYSQL - Fetch Array While Loop

References

About Us

Home
About Us
Contact Us
Sitemap

Tools

Google PageRank
Alexa Rank
Keywords Density

Accounts

Register Account
Login
Valid XHTML 1.0 TransitionalValid CSS!
Web Directory


2006 - 2012 © Leakbali.com - Free Web Tutorial, Free Web Articles, Web Sharing, Source Codes, Web References