Fetch all rows based on the query into an array

浪子不回头ぞ 提交于 2019-12-01 14:40:57
$result = mysql_query("SELECT * FROM $tableName");  
$arr_json = array();
while ($row = mysql_fetch_assoc($result)) {
   $json = json_encode($row);
   $arr_json[] = $json;
}

EDIT: Looking a j08691's answer, it looks like I might have misunderstood.

Anyway, if you don't know how many columns you have, do this:

$arr = array();
while ($row = mysql_fetch_assoc($result)) {
   $arr2 = array();
   foreach ($row as $val) $arr2[] = $val;
   $arr[] = $arr2;
}

Try:

$result = mysql_query("SELECT * FROM $tableName");
while($row = mysql_fetch_array($result)) {
    $array[]=array($row[0], $row[1],...);
}

This will generate a multidimentional array where the subarray contains your values.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!