2013-04-03 86 views
-1

我一直在學習這個,因此我遇到了一個惱人的問題,我似乎無法修復。使用表格時PHP和HTML格式化問題

當內容被回顯到表格而不是創建一個包含內容的表格時,它會創建多個表格。

我越來越:

表1:

  • 頭1 -------- HEADER2
  • achievement1 - 成就 時間

表2:

  • hea der1 -------- HEADER2
  • achievement2 - 成就時

我期待:

表1

  • 頭1 -------- HEADER2
  • 成就1 - 成就時間
  • 成就2 - 成就時間

我試過array_merge,我試着設置成就ID爲關鍵,我甚至嘗試了多個foreach語句,但是這似乎通過重複以及創建額外的表。 如果有人不介意告訴我我做錯了什麼,我會非常感激。

<?php 
// Define cache file 
$cache_file = "cache.txt"; 

// Cache file is less than thirty minutes old. 
if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 60 * 30 ))) { 

// Don't bother refreshing, just use the file as-is. 
$file = file_get_contents($cache_file); 

// Our cache is out-of-date, so load the data from our remote server, 
// and also save it over our cache for next time. 
} else { 
$file = file_get_contents('http://eu.battle.net/api/wow/guild/chamber-of-aspects/requiem%20paradisum?fields=achievements'); 
file_put_contents($cache_file, $file, LOCK_EX); 
} 

// Decode cache file 
$achie = json_decode($file); 

// Seperate achievements and timestamps as variables 
$achiachi = ($achie->achievements->achievementsCompleted); 
$achitime = ($achie->achievements->achievementsCompletedTimestamp); 
foreach(array_combine($achiachi, $achitime) as $f => $n){ 

// Combine achievement number into Link for wowhead script 
$achilink = ("http://www.wowhead.com/achievement=". $f); 

// Sort out time formatting 
$unix = ($n); 
$not_unix = $unix/1000; 
$date = date("F d Y @ h:i A", $not_unix); 

//Print into table 
echo " 
<table align=center class=mytable cellpadding=8 style=font-family:verdana;font-size:8pt;color:white;> 
<tr> 
     <th>Achievement</th><th>Timestamp</th> 
<tr> 
     <td><a href=\"$achilink\" rel=\"item=$achiachi\"></a></td> 
     <td>$date</td> 
</tr> 
</table> 
"; 
} 
?> 

回答

0

爲什麼不把表和th標籤圈外?:

echo "<table align=center class=mytable cellpadding=8 style=font-family:verdana;font-size:8pt;color:white;>"; 
echo "<tr><th>Achievement</th><th>Timestamp</th></tr>"; 
foreach(array_combine($achiachi, $achitime) as $f => $n){ 

// Combine achievement number into Link for wowhead script 
$achilink = ("http://www.wowhead.com/achievement=". $f); 

// Sort out time formatting 
$unix = ($n); 
$not_unix = $unix/1000; 
$date = date("F d Y @ h:i A", $not_unix); 

//Print into table 
echo "<tr> 
     <td><a href=\"$achilink\" rel=\"item=$achiachi\"></a></td> 
     <td>$date</td> 
</tr>"; 
} 
echo "</table>"; 
+0

我其實只是跳舞的一點。你是個明星。 –

0

我認爲你必須呼應和第一的頭outsite for循環