2

我有一个数组,其中包含从两个游戏服务器查询的信息。它看起来像这样:

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  
    ) 
)

然后我有一个表格,显示数组中的信息。但是,目前它在表的同一行上显示两台服务器。该表如下所示:

<?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>';
?>

所以目前它在表的同一行上打印“测试服务器 1”和“测试服务器 2”。如何制作一个表格,将两个数组分别分隔在一行上?

在这里你可以看到表格:http: //zfrag.se/servers.php

4

1 回答 1

4

像这样:

<?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>';
?>
于 2013-05-12T18:43:28.113 回答