laravel cannot display jsondata











up vote
0
down vote

favorite












I'm try to use jsondata to display the results.

This is my output.
Now i just try to display the result



enter image description here



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$json = json_decode($justResults, true);


$aQuestions = array();
$aAnswers = array();
foreach($json as $sKey => $oItem) {
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


in pure php i just use a but in the laravel it's not work.



<div class="container"> 
<table class="table table-striped">
<thead>
<tr>
<?php foreach($aQuestions as $aQuestionsn){?>
<th scope="col"><?php echo $aQuestionsn; ?></th>
<?php }?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach($aAnswers as $aAnswersn) {?>
<td><?php echo $aAnswersn;?></td>
<?php }?>
</tr>
</tbody>
</table>
</div>


How i can display the jsonstring ?



All i need look like this



enter image description here










share|improve this question
























  • use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
    – Istiaque Ahmed
    yesterday












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    yesterday










  • How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
    – Yoram de Langen
    yesterday










  • I just saved the string.
    – Bunyarit Toshuko
    yesterday















up vote
0
down vote

favorite












I'm try to use jsondata to display the results.

This is my output.
Now i just try to display the result



enter image description here



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$json = json_decode($justResults, true);


$aQuestions = array();
$aAnswers = array();
foreach($json as $sKey => $oItem) {
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


in pure php i just use a but in the laravel it's not work.



<div class="container"> 
<table class="table table-striped">
<thead>
<tr>
<?php foreach($aQuestions as $aQuestionsn){?>
<th scope="col"><?php echo $aQuestionsn; ?></th>
<?php }?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach($aAnswers as $aAnswersn) {?>
<td><?php echo $aAnswersn;?></td>
<?php }?>
</tr>
</tbody>
</table>
</div>


How i can display the jsonstring ?



All i need look like this



enter image description here










share|improve this question
























  • use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
    – Istiaque Ahmed
    yesterday












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    yesterday










  • How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
    – Yoram de Langen
    yesterday










  • I just saved the string.
    – Bunyarit Toshuko
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm try to use jsondata to display the results.

This is my output.
Now i just try to display the result



enter image description here



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$json = json_decode($justResults, true);


$aQuestions = array();
$aAnswers = array();
foreach($json as $sKey => $oItem) {
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


in pure php i just use a but in the laravel it's not work.



<div class="container"> 
<table class="table table-striped">
<thead>
<tr>
<?php foreach($aQuestions as $aQuestionsn){?>
<th scope="col"><?php echo $aQuestionsn; ?></th>
<?php }?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach($aAnswers as $aAnswersn) {?>
<td><?php echo $aAnswersn;?></td>
<?php }?>
</tr>
</tbody>
</table>
</div>


How i can display the jsonstring ?



All i need look like this



enter image description here










share|improve this question















I'm try to use jsondata to display the results.

This is my output.
Now i just try to display the result



enter image description here



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$json = json_decode($justResults, true);


$aQuestions = array();
$aAnswers = array();
foreach($json as $sKey => $oItem) {
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


in pure php i just use a but in the laravel it's not work.



<div class="container"> 
<table class="table table-striped">
<thead>
<tr>
<?php foreach($aQuestions as $aQuestionsn){?>
<th scope="col"><?php echo $aQuestionsn; ?></th>
<?php }?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach($aAnswers as $aAnswersn) {?>
<td><?php echo $aAnswersn;?></td>
<?php }?>
</tr>
</tbody>
</table>
</div>


How i can display the jsonstring ?



All i need look like this



enter image description here







php json laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









Bunyarit Toshuko

188




188












  • use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
    – Istiaque Ahmed
    yesterday












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    yesterday










  • How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
    – Yoram de Langen
    yesterday










  • I just saved the string.
    – Bunyarit Toshuko
    yesterday


















  • use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
    – Istiaque Ahmed
    yesterday












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    yesterday










  • How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
    – Yoram de Langen
    yesterday










  • I just saved the string.
    – Bunyarit Toshuko
    yesterday
















use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
– Istiaque Ahmed
yesterday






use $json = json_encode($justResults, JSON_HEX_QUOT | JSON_HEX_APOS); instead of $json = json_decode($justResults, true); if you really need to make any json data. BTW why do you need json in your case? You can just pass the array from controller to view.
– Istiaque Ahmed
yesterday














look at my edit It's will answer your questions
– Bunyarit Toshuko
yesterday




look at my edit It's will answer your questions
– Bunyarit Toshuko
yesterday












How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
– Yoram de Langen
yesterday




How does your data column look like when it is saved? If it's escaped with " it probably means your JSON is encoded twice.
– Yoram de Langen
yesterday












I just saved the string.
– Bunyarit Toshuko
yesterday




I just saved the string.
– Bunyarit Toshuko
yesterday












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










well i think in your case there is another array inside your array you need to go inside that array



foreach($aAnswers as $aAnswersn)
{
foreach ($aAnswersn as $value)
{
echo $value;
}
}





share|improve this answer





















  • it's work thank you
    – Bunyarit Toshuko
    yesterday


















up vote
0
down vote













At least your json_encode is possibly in the wrong location, try this:



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$aQuestions = array();
$aAnswers = array();
// $justResults is a collection so loop through it
foreach($justResults as $sKey => $oItem) {
// $oItem is possibly JSON encoded at this stage
$oItem = json_decode($oItem, true);
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


Please note all changes






share|improve this answer





















  • I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
    – Bunyarit Toshuko
    yesterday













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372264%2flaravel-cannot-display-jsondata%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










well i think in your case there is another array inside your array you need to go inside that array



foreach($aAnswers as $aAnswersn)
{
foreach ($aAnswersn as $value)
{
echo $value;
}
}





share|improve this answer





















  • it's work thank you
    – Bunyarit Toshuko
    yesterday















up vote
1
down vote



accepted










well i think in your case there is another array inside your array you need to go inside that array



foreach($aAnswers as $aAnswersn)
{
foreach ($aAnswersn as $value)
{
echo $value;
}
}





share|improve this answer





















  • it's work thank you
    – Bunyarit Toshuko
    yesterday













up vote
1
down vote



accepted







up vote
1
down vote



accepted






well i think in your case there is another array inside your array you need to go inside that array



foreach($aAnswers as $aAnswersn)
{
foreach ($aAnswersn as $value)
{
echo $value;
}
}





share|improve this answer












well i think in your case there is another array inside your array you need to go inside that array



foreach($aAnswers as $aAnswersn)
{
foreach ($aAnswersn as $value)
{
echo $value;
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Adnan Rasheed

13913




13913












  • it's work thank you
    – Bunyarit Toshuko
    yesterday


















  • it's work thank you
    – Bunyarit Toshuko
    yesterday
















it's work thank you
– Bunyarit Toshuko
yesterday




it's work thank you
– Bunyarit Toshuko
yesterday












up vote
0
down vote













At least your json_encode is possibly in the wrong location, try this:



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$aQuestions = array();
$aAnswers = array();
// $justResults is a collection so loop through it
foreach($justResults as $sKey => $oItem) {
// $oItem is possibly JSON encoded at this stage
$oItem = json_decode($oItem, true);
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


Please note all changes






share|improve this answer





















  • I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
    – Bunyarit Toshuko
    yesterday

















up vote
0
down vote













At least your json_encode is possibly in the wrong location, try this:



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$aQuestions = array();
$aAnswers = array();
// $justResults is a collection so loop through it
foreach($justResults as $sKey => $oItem) {
// $oItem is possibly JSON encoded at this stage
$oItem = json_decode($oItem, true);
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


Please note all changes






share|improve this answer





















  • I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
    – Bunyarit Toshuko
    yesterday















up vote
0
down vote










up vote
0
down vote









At least your json_encode is possibly in the wrong location, try this:



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$aQuestions = array();
$aAnswers = array();
// $justResults is a collection so loop through it
foreach($justResults as $sKey => $oItem) {
// $oItem is possibly JSON encoded at this stage
$oItem = json_decode($oItem, true);
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


Please note all changes






share|improve this answer












At least your json_encode is possibly in the wrong location, try this:



public function resultsurvey($survey_id)
{
//$results=;

$allResults= Results::where('survey_id', $survey_id)->get()->toArray();
$justResults=Results::select('results')->where('survey_id', $survey_id)->get();

$aQuestions = array();
$aAnswers = array();
// $justResults is a collection so loop through it
foreach($justResults as $sKey => $oItem) {
// $oItem is possibly JSON encoded at this stage
$oItem = json_decode($oItem, true);
array_push($aQuestions, $sKey);
array_push($aAnswers, $oItem);
}

dd($aQuestions , $aAnswers);
}


Please note all changes







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Yoram de Langen

3,82611524




3,82611524












  • I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
    – Bunyarit Toshuko
    yesterday




















  • I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
    – Bunyarit Toshuko
    yesterday


















I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
– Bunyarit Toshuko
yesterday






I can't display my code is <div class="container"> <table class="table table-striped"> <thead> <tr> <?php foreach($aQuestions as $aQuestionsn){?> <th scope="col"><?php echo $aQuestionsn; ?></th> <?php }?> </tr> </thead> <tbody> <tr> <?php foreach($aAnswers as $aAnswersn) {?> <td><?php echo $aAnswersn;?></td> <?php }?> </tr> </tbody> </table> </div>
– Bunyarit Toshuko
yesterday




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372264%2flaravel-cannot-display-jsondata%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen