2

I got an array that holds info that is being queried from two game servers. It looks like this:

Array ( 
    [PERP] => Array ( 
        [gq_address] => 192.168.1.1 
        [gq_dedicated] => d 
        [gq_gametype] => 
        [gq_hostname] => Test Server 1
        [gq_mapname] => gm_construct 
        [gq_maxplayers] => 60 
        [gq_mod] => garrysmod 
        [gq_numplayers] => 11 
        [gq_online] => 1 
        [gq_password] => 0 
        [gq_port] => 27016 
        [gq_protocol] => source 
        [gq_transport] => udp 
        [gq_type] => gmod
    )

    [TTT] => Array ( 
        [gq_address] => 192.168.1.1
        [gq_dedicated] => d 
        [gq_gametype] => 
        [gq_hostname] => Test Server 2
        [gq_mapname] => gm_construct 
        [gq_maxplayers] => 30 
        [gq_mod] => garrysmod 
        [gq_numplayers] => 0 
        [gq_online] => 1 
        [gq_password] => 0 
        [gq_port] => 27029 
        [gq_protocol] => source 
        [gq_transport] => udp 
        [gq_type] => gmod  
    ) 
)

And then I have a table that shows the information in the array. However, currently it's showing both servers on the same row in the table. The table looks like this:

<?php
echo '<table cellpadding="1" cellspacing="1" border="1">';
echo '<tr>';

foreach($results as $perp) { 
    echo '<td>' . $perp['gq_type'] . '</td>';
    echo '<td>' . $perp['gq_online'] . '</td>';
    echo '<td>' . $perp['gq_hostname'] . '</td>';
    echo '<td>' . $perp['gq_address'] . '</td>';
    echo '<td>' . $perp['gq_port'] . '</td>';
    echo '<td>' . $perp['gq_numplayers'] . '</td>';
    echo '<td>' . $perp['gq_mapname'] . '</td>';
}

echo '</tr>';
echo '</table>';
?>

So currently it's printing both the "Test Server 1" and "Test Server 2" on the same row in the table. How do I make a table that separates the two arrays on one row each?

Here you can see the table : http://zfrag.se/servers.php

1
  • 4
    Put the <tr> and </tr> in the foreach loop. Commented May 12, 2013 at 18:42

1 Answer 1

4

Like this:

<?php
echo '<table cellpadding="1" cellspacing="1" border="1">';

foreach($results as $perp) { 
    echo '<tr>';
    echo '<td>' . $perp['gq_type'] . '</td>';
    echo '<td>' . $perp['gq_online'] . '</td>';
    echo '<td>' . $perp['gq_hostname'] . '</td>';
    echo '<td>' . $perp['gq_address'] . '</td>';
    echo '<td>' . $perp['gq_port'] . '</td>';
    echo '<td>' . $perp['gq_numplayers'] . '</td>';
    echo '<td>' . $perp['gq_mapname'] . '</td>';
    echo '</tr>';
}

echo '</table>';
?>
Sign up to request clarification or add additional context in comments.

1 Comment

You should output this to an image, then it can be used a signature. Very cool.

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.