1
Array ( [0] => stdClass Object ( 
                  [logtime] => 1305732210 
                  [useragent] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0 
                  [remotehost] => 188-24-176-75.rdsnet.ro 
                  [page] => RSS.php 
                  [qs] => [action] => view page )

        [1] => stdClass Object ( 
                  [logtime] => 1305732216 
                  [useragent] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0 
                  [remotehost] => 188-24-176-75.rdsnet.ro 
                  [page] => Pages.php 
                  [qs] => page=angajari 
                  [action] => view page ) 
)

How to display this array as a table

             **| crt |logtime | useragent  | remotehost | action |
             ---------------------------------------------------
array values |  1  |        |            |            |        |
             ---------------------------------------------------
array values |  2  |        |            |            |        |
             ---------------------------------------------------**
0

3 Answers 3

2
echo '<table><tr><th>....';
foreach($arr as $o){
  echo >>>EOTR
<tr>
  <td>{$o->logtime}</td>
  <td>{$o->useragent}</td>
  <td>{$o->remotehost}</td>
  <td>{$o->page}</td>
  <td>{$o->action}</td>
</tr>
EOTR;
}
echo '</table>';
Sign up to request clarification or add additional context in comments.

1 Comment

both metod works but I have following problem: to store in mysql table this array I need to json_encode - then I use json_decode to array.I think the errors comes in decode function to 'qs' element ex.[qs] => page=angajari has '=';
2

dnagirl's method works, but here's "template format", in case you need it that way (note: replace <?= with <?php echo if you don't have control of your server and/or PHP's short_tags is turned off):

<table><tr><th>
<?php foreach($arr as $o): ?>

<tr>
  <td><?= $o->logtime ?></td>
  <td><?= $o->useragent ?></td>
  <td><?= $o->remotehost ?></td>
  <td><?= $o->page ?></td>
  <td><?= $o->action ?></td>
</tr>
<?php endforeach; ?>
</table>

1 Comment

both metod works but I have following problem: to store in mysql table this array I need to json_encode - then I use json_decode to array.I think the errors comes in decode function to 'qs' element ex.[qs] => page=angajari has '=';
1

edit: sorry, i've totally missed that that's an object inside the array. this solution is wrong.

this would be the more general solution.

echo '<table><tr><td>crt</td>';
    foreach($arr[0] as $key => $val1){
      echo "<td>$key</td>";
    }
    echo '</tr>';
    foreach($arr as $key => $val){
      echo " <tr> <td>".($key+1)."</td>";
        foreach($val as $key => $val1){
          echo "<td>$val1</td>";
        }
      echo " </tr> ";
    }
    echo '</table>';

Comments

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.