Retrieve Multiple Values using Json webservices

02:32:00 0 Comments



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

Joel

Joel Fernandes,I am a Very Smart,Innovative Creative and One of the Best Webdevelopers.I am an expert in Webdevelopment.My other interest include Cars and Vehicles.My desire is to be the best and serve you with the best information I have .I will always share all my tips and tricks on this website and provide you with the best themes so that your life may be simpler.Keep visiting www.joelwebsites.com for the best website related ,tips and tricks and news.Meet me on FaceBook

0 comments: