mysql - Whats the best way to add arrays in php dynamically -


i iterating on data dynamically. data contains 3 fields want insert array.. array(field1,field2,field3)..and insert array array (nest it). nest array main array. problem dont know how 1 array out of loop contain nested arrays.

$myarray=array();   while($row=mysql_fetch_array($result))     {         $myarray+= array(field1,field2,field3);     } 

how add them dynamically..i know wrong way..but how do it?!

while ($row = mysql_fetch_assoc($result1) {     $myarray[] = array($row['field1'], $row['field2'], $row['field3']); } 

if want add whole content of each row, i.e. every field in row, can use

while ($row = mysql_fetch_assoc($result1) {     $myarray[] = $row; } 

or single line:

while ($myarray[] = mysql_fetch_assoc($result)); 

then can access e.g. field2 of row 5 $myarray[4]['field2']

in question use function mysql_fetch_array. please use mysql_fetch_assoc better way. mysql_fetch_array returns every value twice, once numeric index (e.g. 1, note depends on order of queried fields in query!), once associative index. mysql_fetch_assoc returns each value once associative index (e.g. 'field2').


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -