PHP Function Lookup:
PHP Quick Start
PHP Installation
PHP Articles
PHP Scripts

Top Rated Articles 

Site Related
Submit Articles/Code
Contact Us
Instant cash loans, cash advance online same day

   Home                   Article Added on: May 5, 2002
Retrieving multiple rows for data from a table

In the earlier tutorial we have retrieved a single row from a table, In this section we will learn how to retrieve multiple rows of data from a table.

As you have seen earlier we have used the function mysql_fetch_row to retrieve a single rows we use the mysql_fetch_array function to retrieve multiple rows from a table.

Here is an example where we retrieve the entire contents from our jokes table using mysql_fetch_array


$db = mysql_connect("localhost","root","pass");
//replace the above values with your actual database values

$sql_result = mysql_query("SELECT joke_no, joke FROM jokes", $db);

while($rs = mysql_fetch_array($sql_result))
echo "Joke No: $rs[0]<BR>";
echo str_replace("\n","<BR>",$rs[1]);
echo "<P>";

There is nothing special here in the above example, except that mysql_fetch_row is called in a while loop so that it will continue the loop until all the records are displays (SQL Query is completed)

The mysql_fetch_array function accepts a result set as a parameter (stored in the $sql_result variable in this case), and returns the next row in the result set as an array this continues until there are no more rows in the result set when there are no more rows left mysql_fetch_array returns false which exits the loop.

    Send this Article to your Friend!
Your Name Friend's Email
Rate this article:  Current Rating: 1.36
  Poor    Excellent     
          1     2    3    4    5

Other Related articles:


Home | Privacy Policy | Contact Us | Terms of Service
(c) 2002 - 2019 www.PHPbuddy.com Unauthorized reproduction/replication of any part of this site is prohibited.