MYSQL Data -> PHP arrays -> Javascript (or Jquery) How can I pass the data with JSON ?
- by Alex
I am starting with a new site (it's my first one) and I am getting big troubles !
I wrote this code
<?php
include("misc.inc");
$cxn=mysqli_connect($host,$user,$password,$database) or die("couldn't connect to server");
$query="SELECT DISTINCT country FROM stamps";
$result=mysqli_query($cxn,$query) or die ("couldn't execute query");
$numberOfRows=mysqli_num_rows($result);
for ($i=0;$i<$numberOfRows;$i++){
$row=mysqli_fetch_assoc($result);
extract($row);
$a=json_encode($row);
$a=$a.",";
echo $a;
}
?>
and the output is as follows :
{"country":"liechtenstein"},{"country":"romania"},{"country":"jugoslavia"},{"country":"polonia"},
which should be a correct JSON outout ...
How can I get it now in Jquery ? I tried with
$.getJSON
but I am not able to fuse it properly. I don't want yet to pass the data to a DIV or something similar in HTML.
Alex