0
<?php
mysql_pconnect("localhost","root","");
mysql_select_db("AppDevelopMenu") or die( '1');
$sql1=mysql_query("select Question from questions where QId ='1'");

if(!$sql1)
echo '2';

else{

$question=mysql_fetch_assoc($sql1) ;
$outputq[]=$question;


$sql=mysql_query("select OptionId,OptionContent from options where QId ='1'");

if(!$sql)
{
echo '3';
}

else {
while($row=mysql_fetch_assoc($sql))
$outputq[]=$row;
print(json_encode($outputq));
}
}

mysql_close();

?>

i have to modify this code to read json in a different structure that lets say question is the root node..QuestionContent and options are there on next level.And then options is the root node for option1,option2,option3 etc
How should I modify my php code to achieve this

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0

Not sure if this is what you want:

<?php
$qid = 1;
$sql1=mysql_query("select Question from questions where QId = $qid");
if(!$sql1){
    echo '2';
}else{
    $question=mysql_fetch_assoc($sql1) ;
    $outputq['question'] =$question['Question'];
    $sql=mysql_query("select OptionId,OptionContent from options where QId = $qid");
    if(!$sql){
        echo '3';
    }else{
        while($row=mysql_fetch_assoc($sql)){
            $outputq['options'][] = array('id'=>$row['OptionId'], 'content'=>$row['OptionContent']);
        }
    }
    print(json_encode($outputq));
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.