0

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>";
    }
?>
4
  • 1
    where is the starting and ending html code of table? Commented Feb 24, 2014 at 12:17
  • can you please add the output of print_r($data);? So it will be simple to help you. Commented Feb 24, 2014 at 12:18
  • 1
    1. (just as @RamSharma said) Where is the start and end of the table html ? 2. What is the result you get from that code ? Commented Feb 24, 2014 at 12:19
  • thanks gents @krishna helped me with this Commented Feb 24, 2014 at 12:20

2 Answers 2

1

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>"  ;
Sign up to request clarification or add additional context in comments.

Comments

0

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>

1 Comment

you have placed unwanted ?> after every <td> in last row.also this will repeat a same value twice resulting to create two rows with same values

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.