realtek
realtek

Reputation: 841

mysql_fetch_assoc overwrite array

I have the following codewhich basically seems to be overwriting the same array each time so the output (json) only gives me the last row returned?

Thanks

$structure = mysql_query("SELECT FIELDNAME, DISPLAYNAME from `_PREFS_MAINGRID_`");
$rowsField = array();
while($struct = mysql_fetch_assoc($structure)) {
    $rowsField["columname"] = $struct;
}


$plode = implode("` as `", $rowsField["columname"]);

print json_encode($rowsField);

Upvotes: 0

Views: 98

Answers (1)

Amal
Amal

Reputation: 76636

You aren't pushing the elements into the array in your loop.

Try this:

$rowsField["columname"][] = $struct;

See the documentation for more information.

Upvotes: 4

Related Questions