Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and HTML formatting issue when using tables
    text
    copied!<p>I've been learning this by doing and as such I've come across an annoying problem that I can't seem to fix.</p> <p>When the contents are echo'd out to the table instead of creating one table containing the contents it creates multiple tables. </p> <p>I'm getting : </p> <p>Table1 : </p> <ul> <li>header1 -------- header2 </li> <li>achievement1 - achievement time</li> </ul> <p>Table2 : </p> <ul> <li>header1 -------- header2 </li> <li>achievement2 - achievement time</li> </ul> <p>I'm expecting : </p> <p>Table1</p> <ul> <li>header1 -------- header2 </li> <li>achievement1 - achievement time</li> <li>achievement2 - achievement time</li> </ul> <p>I've tried array_merge, I've tried setting the achievement-ID as the key, I even tried multiple foreach statements, but that seems to pull through duplicates as well as creating additional tables. If someone wouldn't mind telling me what I've done wrong I'd be very appreciative.</p> <pre><code>&lt;?php // Define cache file $cache_file = "cache.txt"; // Cache file is less than thirty minutes old. if (file_exists($cache_file) &amp;&amp; (filemtime($cache_file) &gt; (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-&gt;achievements-&gt;achievementsCompleted); $achitime = ($achie-&gt;achievements-&gt;achievementsCompletedTimestamp); foreach(array_combine($achiachi, $achitime) as $f =&gt; $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 " &lt;table align=center class=mytable cellpadding=8 style=font-family:verdana;font-size:8pt;color:white;&gt; &lt;tr&gt; &lt;th&gt;Achievement&lt;/th&gt;&lt;th&gt;Timestamp&lt;/th&gt; &lt;tr&gt; &lt;td&gt;&lt;a href=\"$achilink\" rel=\"item=$achiachi\"&gt;&lt;/a&gt;&lt;/td&gt; &lt;td&gt;$date&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; "; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload