2013-05-12 182 views
1

我試圖插入查詢掃描結果的數組中的某些值。陣列看起來像這樣:將數組值插入到html表中

Array ( 
[PERP] => Array ( 
[Lee_AttachViewModelToView] => 0 
[Lee_WeaponAutoReload] => 0 
[Lee_WeaponDamageMul] => 1 
[Lee_WeaponEDC] => 3 
[Lee_WeaponEDT] => 1 
[Lee_WeaponHitEffect] => 0 
[Lee_WeaponInfiniteAmmo] => 0 
[Lee_WeaponRecoilMul] => 1.4 
[Lee_WeaponShakeMul] => 5 
[Lee_WeaponViewKick] => 1 
[Lee_WeaponsSpeed] => 1 
[ai_disabled] => 0 
[ai_ignoreplayers] => 0 
[coop] => 0 
[deathmatch] => 1 
[decalfrequency] => 10 
[dedicated] => d 
[game_descr] => sandbox 
[game_dir] => garrysmod 
[gq_address] => 192.168.1.1 
[gq_dedicated] => d 
[gq_gametype] => 
[gq_hostname] => Test server 
[gq_mapname] => gm_construct 
[gq_maxplayers] => 60 
[gq_mod] => garrysmod 
[gq_numplayers] => 8 
[gq_online] => 1 
[gq_password] => 0 
[gq_port] => 27016 
[gq_protocol] => source 
[gq_transport] => udp 
[gq_type] => gmod 
[hostname] => Test server 
[map] => gm_construct 
[max_players] => 60 
[mp_allowNPCs] => 1 
[mp_autocrosshair] => 1 
[mp_fadetoblack] => 0 
[mp_falldamage] => 0 
[mp_flashlight] => 1 
[mp_footsteps] => 1 
[mp_forcerespawn] => 1 
[mp_fraglimit] => 0 
[mp_friendlyfire] => 0 
[mp_teamlist] => hgrunt;scientist 
[mp_teamplay] => 0 
[mp_timelimit] => 0 
[mp_weaponstay] => 0 
[nextlevel] => 
[num_bots] => 0 
[num_players] => 8 
[num_rules] => 98 
[os] => w 
[password] => 0 
[physgun_limited] => 0 
[players] => Array ( 

    [0] => Array ( 

     [id] => 0 
     [name] => Supreme Leader Aladeen 
     [score] => 3 
     [time] => 17884.9082031 
     [gq_name] => Supreme Leader Aladeen 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 3 
     [gq_ping] =>) 

    [1] => Array ( 

     [id] => 0 
     [name] => [ZFrag] SpeedDemon 
     [score] => 1 
     [time] => 7439.12109375 
     [gq_name] => [ZFrag] SpeedDemon 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 1 
     [gq_ping] =>) 

    [2] => Array ( 

     [id] => 0 
     [name] => [ZFrag] Swiper The Fox 
     [score] => 0 
     [time] => 7159.75634766 
     [gq_name] => [ZFrag] Swiper The Fox 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 0 
     [gq_ping] =>) 

    [3] => Array ( 

     [id] => 0 
     [name] => {MG} attacker1983 
     [score] => 0 
     [time] => 3252.78735352 
     [gq_name] => {MG} attacker1983 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 0 
     [gq_ping] =>) 

    [4] => Array ( 

     [id] => 0 
     [name] => rolisrolis7 
     [score] => 1 
     [time] => 3240.36376953 
     [gq_name] => rolisrolis7 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 1 
     [gq_ping] =>) 

    [5] => Array ( 

     [id] => 0 
     [name] => T-Bone Jackson 
     [score] => 0 
     [time] => 2755.24243164 
     [gq_name] => T-Bone Jackson 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 0 
     [gq_ping] =>) 

    [6] => Array ( 

     [id] => 0 
     [name] => Maxen #Unban Odx <3 
     [score] => 0 
     [time] => 1802.96948242 
     [gq_name] => Maxen #Unban Odx <3 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 0 
     [gq_ping] =>) 

    [7] => Array ( 

     [id] => 0 
     [name] => the pro pingvin 
     [score] => 0 
     [time] => 814.78704834 
     [gq_name] => the pro pingvin 
     [gq_kills] => 
     [gq_deaths] => 
     [gq_score] => 0 
     [gq_ping] =>)) 

[protocol] => 17 
[r_AirboatViewDampenDamp] => 1.0 
[r_AirboatViewDampenFreq] => 7.0 
[r_AirboatViewZHeight] => 0.0 
[r_JeepViewDampenDamp] => 1.0 
[r_JeepViewDampenFreq] => 7.0 
[r_JeepViewZHeight] => 10.0 
[r_VehicleViewDampen] => 0 
[sb_version] => 1.531 
[sbox_bonemanip_misc] => 0 
[sbox_bonemanip_npc] => 1 
[sbox_bonemanip_player] => 0 
[sbox_godmode] => 1 
[sbox_maxballoons] => 100 
[sbox_maxbuttons] => 50 
[sbox_maxdynamite] => 10 
[sbox_maxeffects] => 200 
[sbox_maxemitters] => 20 
[sbox_maxhoverballs] => 50 
[sbox_maxlamps] => 3 
[sbox_maxlights] => 5 
[sbox_maxnpcs] => 10 
[sbox_maxprops] => 200 
[sbox_maxragdolls] => 10 
[sbox_maxsents] => 300 
[sbox_maxspawners] => 10 
[sbox_maxthrusters] => 50 
[sbox_maxturrets] => 4 
[sbox_maxvehicles] => 3 
[sbox_maxwheels] => 50 
[sbox_noclip] => 1 
[sbox_persist] => 
[sbox_playershurtplayers] => 1 
[sbox_weapons] => 1 
[secure] => 1 
[sensor_debugragdoll] => 0 
[sensor_stretchragdoll] => 0 
[steamappid] => 4000 
[sv_accelerate] => 10 
[sv_airaccelerate] => 10 
[sv_allowcslua] => 0 
[sv_alltalk] => 0 
[sv_bounce] => 0 
[sv_cheats] => 0 
[sv_contact] => 
[sv_footsteps] => 1 
[sv_friction] => 8 
[sv_gravity] => 600 
[sv_hl2mp_item_respawn_time] => 30 
[sv_hl2mp_weapon_respawn_time] => 20 
[sv_maxspeed] => 10000 
[sv_noclipaccelerate] => 5 
[sv_noclipspeed] => 5 
[sv_password] => 0 
[sv_pausable] => 0 
[sv_report_client_settings] => 0 
[sv_rollangle] => 0 
[sv_rollspeed] => 200 
[sv_specaccelerate] => 5 
[sv_specnoclip] => 1 
[sv_specspeed] => 3 
[sv_steamgroup] => 
[sv_stepsize] => 18 
[sv_stopspeed] => 10 
[sv_voiceenable] => 1 
[sv_wateraccelerate] => 10 
[sv_waterfriction] => 1 
[teams] => Array () 
[tv_enable] => 0 
[tv_password] => 0 
[tv_relaypassword] => 0 
[version] => 49)) 

我只想從中選擇某些值; gq_type,gq_online,gq_hostname,gq_address,gq_port,gq_numplayers,gq_mapname。

我想按照上面的順序將這些插入一行的html表中。

問候。

+2

歡迎您!你很清楚你想要什麼,但老實說,我不明白問題是什麼或者這樣做的問題。如果您希望SO社區爲您編寫解決方案,那麼......我有壞消息。 – 2013-05-12 15:39:54

+0

@Stefano:爲什麼壞消息,因爲通常我們會*編碼解決方案。這就是我們*在這裏*爲;儘管在我們嘗試提供幫助之前,有助於清楚地說明問題。 – 2013-05-12 15:47:30

+1

我將編寫一個解決方案,以解決特定的,本地化的問題,OP被卡住了。相反,這看起來像是一種「隱式外包」。也許這不是OP的情況,但我知道一些人(他們反過來並不知道我在做什麼)說:「不要在這個複雜的任務上工作,在SO上發佈,有人會提供免費解決方案!「 – 2013-05-12 15:51:28

回答

0

我想你可以循環您的陣列內,然後你需要你的表裏面的打印數據#2

<table cellpadding="0" cellspacing="0" border="0"> 
    <tr> 
    <?php foreach($array as data) { ?> 
    <td><?php echo $data['gq_type']; ?></td> 
    <td><?php echo $data['gq_online']; ?></td> 
    <td><?php echo $data['gq_hostname']; ?></td> 
    <td><?php echo $data['gq_address']; ?></td> 
    <td><?php echo $data['gq_port']; ?></td> 
    <td><?php echo $data['gq_numplayers']; ?></td> 
    <td><?php echo $data['gq_mapname']; ?></td> 
    <?php } ?> 
    </tr> 
</table> 
+0

不要忘了逃避輸出,以防止XSS - http://php.net/manual/en/function.htmlentities.php – dana 2013-05-12 15:50:31

+0

經過一點編輯,這工作像一個魅力,我永遠感激。 – Amilo 2013-05-12 16:07:53

+0

@Amilo我很高興它的工作,不要忘記也upvote答案! – Fabio 2013-05-12 16:09:04