Note that there are some explanatory texts on larger screens.

plurals
  1. POForeach looping trouble and output
    primarykey
    data
    text
    <p>First off, I am really not that experienced with PHP, and the best practises to use, so please, be nice ;)</p> <p>Anyway, I am struggling with a google analytics output to a java table, where my foreach to display pagehits and pageviews, does not listen to me at all :/</p> <p>Just to clearify, There is nothing wrong with the array, when foreaching values in a regular table, they are correct. I am quite sure there is something with my foreach and perhaps some counting of loops or ?? have no idea?</p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; http://www.google.com/analytics/feeds/data?ga:date=20110930&amp;start-date=2011-09-30&amp;end-date=2011-10-15 [updated] =&gt; 2011-10-14T17:00:00.001-07:00 [title] =&gt; ga:date=20110930 [dimensions] =&gt; Array ( [name] =&gt; date [value] =&gt; 20110930 ) [metrics] =&gt; Array ( [0] =&gt; Array ( [confidenceInterval] =&gt; 0.0 [name] =&gt; newVisits [type] =&gt; integer [value] =&gt; 4 ) [1] =&gt; Array ( [id] =&gt; http://www.google.com/analytics/feeds/data?date=20111001&amp;start-date=2011-09-30&amp;end-date=2011-10-15 [updated] =&gt; 2011-10-14T17:00:00.001-07:00 [title] =&gt; ga:date=20111001 [dimensions] =&gt; Array ( [name] =&gt; date [value] =&gt; 20111001 ) [metrics] =&gt; Array ( [0] =&gt; Array ( [confidenceInterval] =&gt; 0.0 [name] =&gt; newVisits [type] =&gt; integer [value] =&gt; 5 ) [1] =&gt; Array ( [confidenceInterval] =&gt; 0.0 [name] =&gt; uniquePageviews [type] =&gt; integer [value] =&gt; 54 ) ) ) and so on. </code></pre> <p>And now my foreaching: Note: metricsarray => (uniquePageviews + NewVisits), just for the titles</p> <pre><code>&lt;?php if (!empty($metricsArray)): ?&gt; &lt;?php foreach ($metricsArray as $m): ?&gt; &lt;tr&gt; &lt;th&gt;&lt;?php echo $m ?&gt;&lt;/th&gt; &lt;!-- To display UniqueHits and Pageviews titles--&gt; &lt;?php foreach ($account['Account']['dataPoints'] as $data): ?&gt; &lt;?php if (!empty($data['metrics'])): ?&gt; &lt;?php foreach ($data['metrics'] as $key =&gt; $val): ?&gt; &lt;?php if (is_numeric($key)): ?&gt; &lt;td&gt;&lt;?php echo $val['value'] ?&gt;&lt;/td&gt; &lt;?php elseif ($key == 'value'): ?&gt; &lt;td&gt;&lt;?php echo $val ?&gt;&lt;/td&gt; &lt;?php endif ?&gt; &lt;?php endforeach ?&gt; &lt;?php endif ?&gt; &lt;?php endforeach ?&gt; &lt;/tr&gt; &lt;?php endforeach ?&gt; &lt;?php endif ?&gt; </code></pre> <p>My problem is that this output like this:</p> <pre><code>&lt;tr&gt; &lt;th&gt;NewVisits&lt;/th&gt; &lt;td&gt;1&lt;/td&gt; &lt;!-- Unique visit &lt;td&gt;7&lt;/td&gt; &lt;!-- PageViews &lt;td&gt;2&lt;/td&gt; &lt;!-- Uniwue hit &lt;td&gt;7&lt;/td&gt; &lt;!-- PageViews +++++ &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;NUniquePageviews&lt;/th&gt; &lt;td&gt;1&lt;/td&gt; &lt;!-- Unique visit &lt;td&gt;7&lt;/td&gt; &lt;!-- PageViews &lt;td&gt;2&lt;/td&gt; &lt;!-- Uniwue hit &lt;td&gt;7&lt;/td&gt; &lt;!-- PageViews +++++ &lt;/tr&gt; </code></pre> <p>My problem here, is that it display the exact same in both TR, with the exception of the TH title text. It should display Unique vistis only in TR 1, and Pageviews in TR2.</p> <p>Thanks for any input on this..</p> <p>Kind Regards! -Tom</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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