Retrieve Multiple Values using Json webservices
Dear Guys,
In this tutorial I show you how to retrieve multiple Values using Json webservices.
Here below is the code for the get answers file which is the most important which I had explained on the Video
getanswers.php
<?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); ?>
<?php header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT'); ?>
<?php
include_once('confi.php');
error_reporting(E_ALL & ~E_NOTICE);
$uid = isset($_GET['uid']) ? mysql_real_escape_string($_GET['uid']) : "";
if(!empty($uid)){
$qur = mysql_query('SELECT * from app_getanswers ');
$result =array();
while($r = mysql_fetch_array($qur)){
extract($r);
//multiple values will be stored in the result varaible array
$result[] = array("ID" => $id,"question" => $question, "answer" => $answer, "weight" => $weight, "synonyms" => $synonyms, 'other' => $other);
// $json = array("status" => 3, "msg" => "User ID not define");
}
$json = $result;
}else{
$json = array("status" => 0, "msg" => "UID not define");
}
@mysql_close($conn);
/* Output header */
header('Content-type: application/json');
echo json_encode($json);
Now here is the Javascript that is needed to get the data using the for loop
which is really simple
var url = 'http://joethemes.com/chatadmin/webservices/getanswers.php?uid=1';
$.post(url, function(data){
for (var cnt = 0; cnt < data.length; cnt++) {
var ID = data[cnt].ID;
var question = data[cnt].question;
var answer = data[cnt].answer;
var weight = data[cnt].weight;
}
});
I hope that this article helped you ...If yes mention a comment below thank you :) View my Youtube channel here
.png)

0 comments: