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
asked Mar 6, 2014 at 18:52
Terry
5782 gold badges5 silver badges15 bronze badges
1 Answer 1
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);
answered Mar 6, 2014 at 18:54
AbraCadaver
79.2k7 gold badges75 silver badges91 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Terry
both those option worked great thanks i new it had to be something simple
lang-php