0

I am trying to convert a mysql resource id to JSON object to be sent as a response for ajax call this is the code that I´ve tried to use

<?php
require_once 'config.php';
$sql="SELECT * FROM `inquiry` WHERE 1";
$res=mysql_query($sql);
if($res)
echo json_encode($res);
?>

and I get this error message

Warning: [json] (php_json_encode) type is unsupported, encoded as null in /home/smartco/public_html/kb/q.php on line 6

null

how can I do it

1 Answer 1

2

Change your code something to

$res = mysql_query($sql);
while($data = mysql_fetch_array($res)) {
 $output[] = $data;
}
echo json_encode($output);

You're encoding the resource id.

Sign up to request clarification or add additional context in comments.

Comments

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.