看板 PHP 關於我們 聯絡資訊
$sql="SELECT id,classify FROM db; 用 print_r($row); print_r("temp_arr陣列=".$temp_arr); print_r($temp_arr); 分別得到 1.沒東西 2.Array( [0] => Array ( [id] => 1 [classify] => 18 ) [1] => Array ( [id] => 3 [classify] => 20 ) ) 3.temp_arr陣列 =Array[{"id":"1","classify":"18"}] 第三個怎會也只有一個陣列? ----------------------------------- 感謝幫助~ANS: print_r是陣列用的 不能加字 加字用echo php內寫mysql接收資料 while($row = mysql_fetch_array($result)){ $temp[] = $row; } echo json_encode($temp); 出現的會是 [{"id":"1","classify":"18","mes":"good","name":"mary"}, ] 全部的數據 另一個數據 沒有出現? {"id":"3","classify":"20","mes":"bad","name":"candy"} 若我只想要他出現 id 和 classify請問我要怎麼寫 $temp[] = $row; 這位置 PS:若寫 $temp[] = $row[classify]; 就可以出現兩個數據的classify個別出來 如["18","20"] 感謝幫助 ANS:因為我後面用了一個array_unique的只能用在一維陣列 二維陣列不適用 花了一天>__<...感謝大家的幫忙 所以請問想要他出現 [{"id":"1","classify":"18" },[{"id":"3","classify":"20" }] 要怎麼寫呢?感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: higgco (163.30.127.172), 10/26/2017 13:32:01 ※ 編輯: higgco (163.30.127.172), 10/26/2017 13:32:39
Nonegrame: $temp[] = array( 'id' => $row['id'], 'classify' => 10/26 14:15
Nonegrame: $row['classify') 10/26 14:15
higgco: 謝謝成功了 但現在不知為何 只有一列數據 沒有其他數據 10/26 14:41
※ 編輯: higgco (163.30.127.172), 10/26/2017 15:35:42 ※ 編輯: higgco (163.30.127.172), 10/26/2017 17:51:08 ※ 編輯: higgco (163.30.127.172), 10/26/2017 17:51:43
rrr0832: 盡量避免使用mysql_開頭的函數 10/27 09:43
newversion: 下篇回文預測成功! XD 10/27 11:02
anawak: 是"已解決",不是"以解決" 10/29 18:38