2014-03-06 60 views
0

我正在特林得到的查詢字符串ID幾乎工程JSON請求,但它是增加 somesort額外的數組對象PHP json_encode陣列接取

$id = $_GET['id']; 
$result = mysqli_query($con,'SELECT * FROM ContactInfo WHERE id =' . $id); 
$row = mysqli_fetch_array($result); 
echo json_encode($row); 

{"0":"terry","FirstName":"terry","1":"rihoff","LastName":"rieff","2":"alientory","website":"alieory","3":"`123","PhoneNumber":"`123","4":"123","Fax":"123","5":"2","id":"2"} 

我只能得到一個接觸,但看起來像exrtra數組被添加到每個字段

回答

1

mysqli_fetch_array()返回一個數字和字符串鍵的數組,因此您有兩次數據(一次使用數字索引,一次使用字符串索引)。嘗試:

$row = mysqli_fetch_assoc($result); 

或者:

$row = mysqli_fetch_array($result, MYSQLI_ASSOC); 
+0

這兩個選項的工作十分感謝我新它必須是簡單的東西 – Terry