laravel cannot display jsondata
I'm try to use jsondata to display the results.
This is my output.
Now i just try to display the result
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
php json laravel
add a comment |
I'm try to use jsondata to display the results.
This is my output.
Now i just try to display the result
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
php json laravel
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 '18 at 10:10
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 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 '18 at 10:18
I just saved the string.
– user8693711
Nov 19 '18 at 10:20
add a comment |
I'm try to use jsondata to display the results.
This is my output.
Now i just try to display the result
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
php json laravel
I'm try to use jsondata to display the results.
This is my output.
Now i just try to display the result
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
php json laravel
php json laravel
edited Nov 19 '18 at 10:17
asked Nov 19 '18 at 10:04
user8693711
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 '18 at 10:10
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 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 '18 at 10:18
I just saved the string.
– user8693711
Nov 19 '18 at 10:20
add a comment |
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 '18 at 10:10
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 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 '18 at 10:18
I just saved the string.
– user8693711
Nov 19 '18 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 '18 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 '18 at 10:10
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 at 10:18
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 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 '18 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 '18 at 10:18
I just saved the string.
– user8693711
Nov 19 '18 at 10:20
I just saved the string.
– user8693711
Nov 19 '18 at 10:20
add a comment |
2 Answers
2
active
oldest
votes
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;
}
}
it's work thank you
– user8693711
Nov 20 '18 at 2:05
add a comment |
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
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>
– user8693711
Nov 19 '18 at 10:45
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
}
}
it's work thank you
– user8693711
Nov 20 '18 at 2:05
add a comment |
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;
}
}
it's work thank you
– user8693711
Nov 20 '18 at 2:05
add a comment |
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;
}
}
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;
}
}
answered Nov 19 '18 at 10:55
Adnan RasheedAdnan Rasheed
20423
20423
it's work thank you
– user8693711
Nov 20 '18 at 2:05
add a comment |
it's work thank you
– user8693711
Nov 20 '18 at 2:05
it's work thank you
– user8693711
Nov 20 '18 at 2:05
it's work thank you
– user8693711
Nov 20 '18 at 2:05
add a comment |
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
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>
– user8693711
Nov 19 '18 at 10:45
add a comment |
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
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>
– user8693711
Nov 19 '18 at 10:45
add a comment |
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
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
answered Nov 19 '18 at 10:21
Yoram de LangenYoram de Langen
3,91311727
3,91311727
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>
– user8693711
Nov 19 '18 at 10:45
add a comment |
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>
– user8693711
Nov 19 '18 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>
– user8693711
Nov 19 '18 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>
– user8693711
Nov 19 '18 at 10:45
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 '18 at 10:10
look at my edit It's will answer your questions
– user8693711
Nov 19 '18 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 '18 at 10:18
I just saved the string.
– user8693711
Nov 19 '18 at 10:20