2

I am making a table which will fetch data from API. I am able to fetch the first value, How can i use foreach with my code? I am not able to do so.

My Table:

<table class="table table-bordered">
<thead>
    <tr>
        <th>Name</th>
        <th>Steam URL</th>
    </tr>
</thead>
<tbody>
    <tr>
        <th><?php echo $name;?></th>
        <th><?php echo $steam;?></th>
    </tr>
</tbody>
</table>

And My PHP Code:

$name = $json->submissions[0]->data->name;
$steam = $json->submissions[0]->data->steam;

It's showing first value correct but not able to get the second entry.

5
  • Does second entry exists? Commented Jan 25, 2018 at 11:43
  • Yes, It does. API Used: formkeep.com/api/v1/forms/125ae3ee8c6a/submissions.json Commented Jan 25, 2018 at 11:46
  • This URL ask for Username and password! Commented Jan 25, 2018 at 11:47
  • I don't see a foreach() in your code Commented Jan 25, 2018 at 11:59
  • Could you consider undeleting stackoverflow.com/q/54012997/6309? This was a valid question. Commented Jan 3, 2019 at 21:20

1 Answer 1

3

Try this one if it works!

<table class="table table-bordered">
<thead>
    <tr>
        <th>Name</th>
        <th>Steam URL</th>
    </tr>
</thead>
<tbody>
    <?php foreach ($json->submissions as $key => $submission): ?>
        <tr>
            <th><?php echo $submission->data->name;?></th>
            <th><?php echo $submission->data->steam;?></th>
        </tr>
    <?php endforeach ?>
</tbody>
</table>
Sign up to request clarification or add additional context in comments.

2 Comments

Notice: Trying to get property 'data' of non-object in C:\xampp\htdocs\uig\entries.php on line 99
It's working now, BTW please close <table> tag. Ty :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.