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
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 |
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
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 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
add a comment |
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
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 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
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 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
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05
add a comment |
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
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
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05
add a comment |
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;
}
}
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 at 10:55
Adnan Rasheed
19413
19413
it's work thank you
– Bunyarit Toshuko
Nov 20 at 2:05
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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 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
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>
– 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
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.
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.
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 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