Reputation: 1232
I'm trying to convert some old php code that used mysql to using mysqli,
the code I've updated to is:
function mysql_fetch_full_result_array($result){
global $dbc;
$table_result=array();
$r=0;
while($row = mysqli_fetch_assoc($result)){
$arr_row=array();
$c=0;
while ($c < mysqli_num_fields($result)) {
$col = mysqli_fetch_field($result);
$arr_row[$col -> name] = $row[$col -> name];
$c++;
}
$table_result[$r] = $arr_row;
$r++;
}
return $table_result;
}
However, after the first row, it's only outputting null for every value as seen here, i'm sure I'm not incrementing something but I'm not sure where or how at this point:
{"DOMAIN.COM":[{"image":"http:\/\/DOMAIN.COM\/photos\/grid_logo.jpg","source":"logo","user":"","printed":"","note":""},{"image":"http:\/\/DOMAIN.COM\/photos\/grid_block.jpg","source":"block","user":"","printed":"","note":""},{"image":"http:\/\/pbs.twimg.com\/media\/BlNvdcrCAAAlz8-.jpg","source":"twitter","user":"ObserveMeditate","printed":"0","note":"RT @IMSEngage: Moby (@thelittleidiot) sits down with the legendary @DAVID_LYNCH this Wednesday: http:\/\/t.co\/PMn9EHQVcp #IMSEngage http:\/\/t.\u2026"},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null}]}
Upvotes: 0
Views: 72
Reputation: 79024
It appears that what you are attempting to do is the same as this (except with a lot of extraneous code):
while($row = mysqli_fetch_assoc($result)) {
$table_result[] = $row;
}
return $table_result;
Or maybe:
while($row[] = mysqli_fetch_assoc($result)) { }
return $row;
Or even just:
$all_rows = mysqli_fetch_all($result, MYSQLI_ASSOC); //may still be server dependent
Upvotes: 3