I am iterating over data dynamically. The data contains three fields that I want to insert into an array.. Array(field1,field2,field3)..and then insert that array into another array (nest it). Then nest another array into the main array. The problem is that i dont know how to do it so that I get one array out of the loop that will contain all the nested arrays.
$myArray=array();
while($row=mysql_fetch_array($result))
{
$myArray+= Array(field1,field2,field3);
}
How do you add them dynamically..I know I do it the wrong way..But how do you do it?!
If you want to add the whole content of each row, i.e. every field in a row, you can just use
or just this single line:
Then you can access e.g. field2 of row 5 with $myArray[4][‘field2’]
In your question you use the function mysql_fetch_array. Please use mysql_fetch_assoc as this is most certainly the better way. mysql_fetch_array returns every value twice, once with a numeric index (e.g. 1, but note that this depends on the order of the queried fields in your query!), once with an associative index. mysql_fetch_assoc only returns each value once with its associative index (e.g. ‘field2’).