0

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.

1
  • 1
    Where is this "subject" stored? What does var_dump($results); show? Commented Feb 5, 2014 at 18:28

2 Answers 2

2

Try this

foreach ($results['results'] as $item) {
  echo 'id: '. $item['id'] . ' subject: '. $item['subject'] .'<br/>';
}
Sign up to request clarification or add additional context in comments.

6 Comments

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?
If I understood correctly then yes. Just add it before <br/>
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"/>
im guessing theres no way to put html code for a submit button inside that foreach loop? PHP Parse error: syntax error, unexpected '<'
echo '<input type=\"submit\" name=\"ViewTicket\" value=\"'. $item['id'] .'\"/>'; i got it but i think my format is wrong?
|
0
  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

just wanted to see if you have any thoughts? @veNuker
it's probably because you are using it outside foreach loop, read this devzone.zend.com/7/php-101-part-3-looping-the-loop

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.