I have this query
$result = mysql_query("SELECT * FROM ship_data WHERE id = $ship") or die(mysql_error());
$rows = array();
while($r = mysql_fetch_assoc($result)) {
$rows = $r;
echo json_encode($rows);
}
And this bit of ajax to return the results
$.ajax({
type: "POST",
dataType: "json",
data: "ship=" + ship,
cache: false,
url: "/getdata.php",
success: function (data) {
alert(data.carrier);
}
});
If there is just one result in the array it works, if the array has multiple results in the array nothing is alerted.
Change your
whileloop to…And your JavaScript should always iterate over
datawith$.each().