I have trouble to make this function run with decoded json array.
For example, I tried to fetch an array with PDO prepared statement:
*NOTE: $user
is passed with the decoded json array.
public function get_pagnated_qs($user){
////////////////////////Actual
$sth = $this->dbh->prepare("SELECT a.quest_id, a.quest_title, a.quest_desc, b.qcat_name,c.qtype_title FROM eq_question_s AS a INNER JOIN eq_question_category AS b ON a.qcat_id = b.qcat_id INNER JOIN eq_question_type AS c ON a.qtype_id=c.qtype_id ORDER BY quest_id LIMIT ?, ?");
$sth->execute(array($user->start, $user->per_page));
$result = json_encode($sth->fetchAll());
return $result;
}
it will not generate objects (I found out when I echo the object in javasccript side.
On the other hand if I replace the two ?
with actual number (i.e. 0,3
) then everything will work perfectly.
The function is to return $result as an encoded json back to client to process and format into a table.
I do not know if this piece of code have anything wrong?
Lets assume that I have decode the json array correctly back as object, otherwise there will be way too much code to frustrate with.
Maybe just some insight will help, but I do not want to frustrate anyone.
the client side js which take the actual return and generate form (part of the functiOn) is:
function showListOfPaginatedQuestions(jsonData) {
alert('pagED RAN!');
alert(jsonData);
console.log(jsonData);
var table = '<table width="600" cellpadding="5" class="table table-hover table-bordered"><thead><tr><th scope="col">Category</th><th scope="col">Type</th><th scope="col">Question</th><th scope="col">Question Description</th><th scope="col"></th></tr></thead><tbody>';
$.each( jsonData, function( index, user){
table += '<tr>';
table += '<td class="edit" field="qcat_id" user_id="'+user.quest_id+'">'+user.qcat_name+'</td>';
});
$('div#content').html(table);
}
Thank You