Stroes
Stroes

Reputation: 361

Displaying data in table foreach loop

I am calling github api to list all the issues I have in my repo.
I want to list these issues in table form on my site...

However I cannot get the table going with my foreach loop.

Here is my PHP code:

<?php
    ini_set('user_agent', 'PHP');

    $json = file_get_contents("https://api.github.com/repos/stroes/stroestest/issues");
    $data = json_decode($json);

    foreach ($data as $i) {
      // echo $i->number.";".$i->state.";".$i->title.";".$i->body."\n\r";
      echo "<tr><td>".$i->number."</td><td>".$i->state."</td><td>".$i->title."</td><td>".$i->body."</td></tr>";
    }
?>

Upvotes: 0

Views: 2065

Answers (2)

Shahbaz
Shahbaz

Reputation: 3463

Table tag is not there, try this

ini_set('user_agent', 'PHP');
$json = file_get_contents("https://api.github.com/repos/stroes/stroestest/issues");
$data = json_decode($json); ?>
<table>
<?php
foreach ($data as $i)
{
    echo "<tr><td>".$i->number."</td><td>".$i->state."</td><td>".$i->title."</td><td>".$i->body."</td></tr>";
?>
<tr>
    <td> ?>
    <?php echo $i->number ?>.
    </td>
    <td> ?>
    <?php echo $i->state ?>.
    </td>
    <td> ?>
    <?php echo $i->title ?>.
    </td>
    <td> ?>
    <?php echo $i->body ?>.
    </td>
</tr>
<?php
}
?>
</table>

Upvotes: 0

krishna
krishna

Reputation: 4099

You are missing table tag. so try this

ini_set('user_agent', 'PHP');
$json = file_get_contents("https://api.github.com/repos/stroes/stroestest/issues");
$data = json_decode($json);
echo "<table>"   ;
foreach ($data as $i)
{
//    echo $i->number.";".$i->state.";".$i->title.";".$i->body."\n\r";
    echo "<tr><td>".$i->number."</td><td>".$i->state."</td><td>".$i->title."</td><td>".$i->body."</td></tr>";
}
echo "</table>"  ;

Upvotes: 1

Related Questions