我一直在学习这个,因此我遇到了一个恼人的问题,我似乎无法修复。使用表格时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>
";
}
?>
我其实只是跳舞的一点。你是个明星。 –