Forum Moderators: coopster

Message Too Old, No Replies

PHP Array

Passing data into array.

         

shane8960

3:27 pm on Apr 16, 2009 (gmt 0)

10+ Year Member



Hi guys,

I havent used arrays in PHP before (still learning - getting there).

Basically I have a table which contains the following 3 columns:

ID ¦ Value 1 ¦ Value 2

I have pulled all the values I need from the database and performed the necessary function on them, however I now need to insert these into an array.

I just need to know the code to drop in below:

------
while($row = mysql_fetch_array($result)){
# INSERT DATA AT BOTTOM OF ARRAY
}
----------

I would be thankful for any help received.

d40sithui

6:26 pm on Apr 16, 2009 (gmt 0)

10+ Year Member



Looks like you might have to use a 2-dimensional array for this one.

$count = 0;

while($row = mysql_fetch_array($result)){
$myArray[$count][0] = $row[0]; //id
$myArray[$count][1] = $row[1]; // Value 1
$myArray[$count][2] = $row[2]; // Value 2

$count++;
}

//printing the array


for($i = 0; $i < sizeof($myArray); $i++){
echo "\$myArray[$i][0]: ".$myArray[$i][0]."<br>";
}

shane8960

8:34 pm on Apr 16, 2009 (gmt 0)

10+ Year Member



Thanks for that - looks like it should work and I'll give it a go later.

Thanks, Shane