I have working code,
$output=json_encode($data);
$results=json_decode($output, TRUE);
foreach ($results['results'] as $id) {
echo $id['id'] . '<br/>';
}
But what i am trying to do is list not only the ID's of the JSON output but also the "subject" Associated with each ID right next or below it. not sure how to do so.
2 Answers 2
Try this
foreach ($results['results'] as $item) {
echo 'id: '. $item['id'] . ' subject: '. $item['subject'] .'<br/>';
}
answered Feb 5, 2014 at 18:30
lchachurski
1,82018 silver badges22 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
user3100345
I KNOW this is a step beyond it, but the way i am displaying this is with a form. Is there a way after this is done that on the results page i can have a Button to display that specific "Ticket"? a click view on the right side of each line?
lchachurski
If I understood correctly then yes. Just add it before <br/>
user3100345
i just tried to add it as a submit button but of course that didnt work. i basically have in the script an if statement from a previous page <form action="submit.php" method="post"> <input type="text" name="ID" value="ID"/>
user3100345
im guessing theres no way to put html code for a submit button inside that foreach loop? PHP Parse error: syntax error, unexpected '<'
user3100345
echo '<input type=\"submit\" name=\"ViewTicket\" value=\"'. $item['id'] .'\"/>'; i got it but i think my format is wrong?
|
echo "<form action=\"former.php\" method=\"post\">";
echo '<input type="text" name="TicketID" value="'. $item['id'] .'"/>';
echo "<input type=\"submit\" name=\"View\" value=\"View\" />";
the Above is working for me BUT it wont let me view the Specific ID . it just defaults to the last ID in the array. @veNuker
2 Comments
user3100345
just wanted to see if you have any thoughts? @veNuker
lchachurski
it's probably because you are using it outside foreach loop, read this devzone.zend.com/7/php-101-part-3-looping-the-loop
lang-php
var_dump($results);show?