Stroes Stroes - 4 months ago 12
HTML Question

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>";
}
?>

Answer

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>"  ;