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
    Nov 19 at 10:10












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    Nov 19 at 10:18










  • 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
    Nov 19 at 10:18










  • I just saved the string.
    – Bunyarit Toshuko
    Nov 19 at 10:20















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
    Nov 19 at 10:10












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    Nov 19 at 10:18










  • 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
    Nov 19 at 10:18










  • I just saved the string.
    – Bunyarit Toshuko
    Nov 19 at 10:20













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 Nov 19 at 10:17

























asked Nov 19 at 10:04









Bunyarit Toshuko

198




198












  • 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
    Nov 19 at 10:10












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    Nov 19 at 10:18










  • 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
    Nov 19 at 10:18










  • I just saved the string.
    – Bunyarit Toshuko
    Nov 19 at 10:20


















  • 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
    Nov 19 at 10:10












  • look at my edit It's will answer your questions
    – Bunyarit Toshuko
    Nov 19 at 10:18










  • 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
    Nov 19 at 10:18










  • I just saved the string.
    – Bunyarit Toshuko
    Nov 19 at 10:20
















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
Nov 19 at 10:10






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
Nov 19 at 10:10














look at my edit It's will answer your questions
– Bunyarit Toshuko
Nov 19 at 10:18




look at my edit It's will answer your questions
– Bunyarit Toshuko
Nov 19 at 10:18












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
Nov 19 at 10:18




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
Nov 19 at 10:18












I just saved the string.
– Bunyarit Toshuko
Nov 19 at 10:20




I just saved the string.
– Bunyarit Toshuko
Nov 19 at 10:20












2 Answers
2






active

oldest

votes

















up vote
2
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
    Nov 20 at 2:05


















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
    Nov 19 at 10:45













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
2
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
    Nov 20 at 2:05















up vote
2
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
    Nov 20 at 2:05













up vote
2
down vote



accepted







up vote
2
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 Nov 19 at 10:55









Adnan Rasheed

19413




19413












  • it's work thank you
    – Bunyarit Toshuko
    Nov 20 at 2:05


















  • it's work thank you
    – Bunyarit Toshuko
    Nov 20 at 2:05
















it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05




it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05












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
    Nov 19 at 10:45

















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
    Nov 19 at 10:45















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 Nov 19 at 10:21









Yoram de Langen

3,87611626




3,87611626












  • 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
    Nov 19 at 10:45




















  • 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
    Nov 19 at 10:45


















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
Nov 19 at 10:45






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
Nov 19 at 10:45




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

Costa Masnaga

Fotorealismo

Sidney Franklin