Using PHP to place database rows into an array?

Posted by Hamed Szilazi on Stack Overflow See other posts from Stack Overflow or by Hamed Szilazi
Published on 2010-05-16T17:42:23Z Indexed on 2010/05/16 17:50 UTC
Read the original article Hit count: 301

Filed under:
|
|

I was just wondering how i would be able to code perform an SQL query and then place each row into a new array, for example, lets say a table looked like the following:

$people= mysql_query("SELECT * FROM friends")    

Output:

| ID | Name | Age |   
--1----tom----32   
--2----dan----22   
--3----pat----52   
--4----nik----32   
--5----dre----65

How could i create a multidimensional array that works in the following way, the first rows second column data could be accessed using $people[0][1] and fifth rows third column could be accessed using $people[4][2].

How would i go about constructing this type of array?

Sorry if this is a strange question, its just that i am new to PHP+SQL and would like to know how to directly access data. Performance and speed is not a issue as i am just writing small test scripts to get to grips with the language.

© Stack Overflow or respective owner

Related posts about php

Related posts about sql