I have a php script that fetches a table values from mysql (one row). & echoes it as JSON.
"<?php
$username = "user";
$password = "********";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect
to MySQL");
selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");
$query = "SELECT * FROM user_spec";
$result=mysql_query($query);
$data = array();
while ($row = mysql_fetch_assoc($result))
{ $data = $row; }
echo json_encode($data);
?> "
this php code outputs {"options":"abc"} that is last row in this column.
In HTML file, I have to receive this data through $.getJSON, but I am not able to get it. It outputs as 'undefined'. Here is HTML:
"<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/lib…
<script type="text/javascript" language="javascript">
//$('document').ready(function() {
function Preload() {
$.getJSON("http://localhost/conn_mysql.p… function(json){
for(var row in json){alert(row.options);}
});} // });
</script></head>
<body onLoad="Preload()">
</body>
</htm
"<?php
$username = "user";
$password = "********";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect
to MySQL");
selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");
$query = "SELECT * FROM user_spec";
$result=mysql_query($query);
$data = array();
while ($row = mysql_fetch_assoc($result))
{ $data = $row; }
echo json_encode($data);
?> "
this php code outputs {"options":"abc"} that is last row in this column.
In HTML file, I have to receive this data through $.getJSON, but I am not able to get it. It outputs as 'undefined'. Here is HTML:
"<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/lib…
<script type="text/javascript" language="javascript">
//$('document').ready(function() {
function Preload() {
$.getJSON("http://localhost/conn_mysql.p… function(json){
for(var row in json){alert(row.options);}
});} // });
</script></head>
<body onLoad="Preload()">
</body>
</htm