0

I have the following code in my PHP program:

$query = "SELECT * FROM board_members";
$result = mysql_query($query) or die(mysql_error());        
$data = array(); // create a variable to hold the information
while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false){
  $data[] = $row; // add the row in to the results (data) array
}

print_r($data); // print result

This give me the following corrrect data for the table:
Array ( [0] => Array ( [FirstName] => Alona [LastName] => Burnett [Amount] => 1000.00 ) [1] => Array ( [FirstName] => Anna Marie [LastName] => Hartman [Amount] => 1200.00 ) [2] => Array ( [FirstName] => Anne [LastName] => Ferguson [Amount] => 500.00 ) [3] => Array ( [FirstName] => Bobbie [LastName] => McLaughlin [Amount] => 900.00 )

How can I echo for example the third person's FirstName, then LastName, then Amount?
I would like to use something like echo $data[FirstName][2] to get the first name from the 3rd row.

Edited by Mike_H

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mike_H
0

Following way you can refer third record (index=2).

echo "Third person: ".$data[2]['FirstName']." ".$data[2]['LastName']."-".$data[2]['Amount'];
0

Thanks urtrivedi!

That works - just what I was looking for.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.