Ok I've got this code in a file test.php:
<?php
$con = mysqli_connect("localhost", "user", "password", "DB");
if (mysqli_connect_errno()){
echo "failed to connect:" . mysqli_connect_error();
}
$grab = mysqli_query($con, "SELECT * FROM DB");
$cars = array();
while($row = mysqli_fetch_assoc($grab)){
array_push($cars, array("id" => $row["Id"], "name" => $row["Name"], "color" => $row["Color"];
}
echo json.encode($cars);
And I've got the jQuery code on my HTML page:
$.get("test.php", function($cars){
$("itemNameLink1").html($cars.name);
console.log($cars.name);
});
My next question is how do I access the data in my json_encoded array and use it in my jQuery on the HTML page. Right now I only get back undefined in console log. It was only my first try so wasn't disheartened by it. But any advise would be appreciated.
json.encode? that a typo?, any way, you need to loop the response, since this is most likely to have many rowscarsis an array ? you are accessingname, which is probably a property of an individual car, not of the array.console.log($cars);?