I have the following php code:
<?php
$servername = "host";
$username = "user";
$password = "passw";
$dbname = "dbname";
$conn3 = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn3->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q3 = $conn3->prepare("SELECT c.one, c.two FROM table c");
$q3->execute();
if($q3->rowCount()>0)
{
$check3 = $q3->fetchAll(PDO::FETCH_ASSOC);
$arr = array();
foreach ($check3 as $row) {
$arr[] = $row;
//how can I return json format here?
}
}
$conn2 = null;
?>
and this query returns pairs of elements. But how can I modify the code above to get the json format of the elements as:
{key1:OSO;key2:AIKA} etc.
so that I can use it later in a jquery file to print it with the following fuction:
$.getJSON('list.php', function(json) {
//assuming list.php resides with list.html directory
//console.log(json)
console.log(json.result.key1);
console.log(json.result.key2);
});
thanks!