Possible Duplicate:
Taking .get json string, turn into array?
Im using the following to retrieve a string from php, i would like to know how to make my string into an array.
Jquery
$.get("get.php", function(data){
alert(data);
//alert($.parseJSON(data));
}, "json");
the commented out section seems to have no effect, so I cant really tell what I am doing wrong, could someone please advice?
PHP
<?php
$username="root";
$password="root";
$database="testing";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$name= $_GET['name'];
$query="SELECT * FROM tableone ";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$array = array();
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"firstname");
$last=mysql_result($result,$i,"lastname");
$date=mysql_result($result,$i,"date");
$ID=mysql_result($result,$i,"id");
$array[$i] = $first;
$i++;
}
echo json_encode($array);
?>
Output:
["James","Lydia","John"]