OK, so I want to get a row of data from a DB via jQuery.ajax()
Here is the code where I want to load it:
$.ajax({
url: 'mypage.php?id=345',
success: function(data) {
//process array of data
}
});
Here is the code on the page that jQuery is loading from:
$DBH = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$STH = $DBH->("SELECT * FROM mytable WHERE id = :id");
$STH->setFetchMode(PDO::FETCH_ASSOC);
$data = array( 'id' => $_GET['id']);
$returnArray = $STH->fetch($data);
// How do I return $returnArray as an Array to jquery?
Not sure what to do to return the array. I guess I can implode() it as a string and then split() once returned but I thought there might be a better way.
Also, I am new to using PDO so if I did it wrong please let me know. Thanks.