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
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
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 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
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
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
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
yesterday
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
yesterday
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
yesterday
add a comment |
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;
}
}
it's work thank you
– Bunyarit Toshuko
yesterday
add a comment |
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;
}
}
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 yesterday
Adnan Rasheed
13913
13913
it's work thank you
– Bunyarit Toshuko
yesterday
add a comment |
it's work thank you
– Bunyarit Toshuko
yesterday
it's work thank you
– Bunyarit Toshuko
yesterday
it's work thank you
– Bunyarit Toshuko
yesterday
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
yesterday
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
yesterday
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 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
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
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
add a comment |
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
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