Reputation: 578
i am tring to get a json request from query string id it almost works but it is adding somesort of extra array object
$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"}
i should only be getting one contact but looks like exrtra array being add to each field
Upvotes: 0
Views: 56
Reputation: 78994
mysqli_fetch_array()
returns an array with numeric and string keys so you have the data twice (once with a numeric index and once with a string index). Try:
$row = mysqli_fetch_assoc($result);
Or:
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
Upvotes: 1