0

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

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

both those option worked great thanks i new it had to be something simple

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.