Hi,<div><br class="webkit-block-placeholder"></div><div>I&#39;m currently building a search page for computer games and have come across some teething problems whilst using freebase.</div><div><br class="webkit-block-placeholder">
</div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">$q = array(</span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">
&quot;type&quot; =&gt; &quot;/cvg/cvg_platform&quot;,</span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">&quot;name&quot; =&gt; &quot;Xbox 360&quot;,</span></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">&quot;games_on_this_platform&quot; =&gt; array(&quot;game&quot; =&gt; array(&quot;name&quot; =&gt; null))</span></div><div>
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">);</span></div><div><br class="webkit-block-placeholder"></div><div>This is the query I based that on from within the freebase query builder:
</div><div><br class="webkit-block-placeholder"></div><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; "><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">[{</span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; "><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">&quot;type&quot;:&quot;/cvg/cvg_platform&quot;,</span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; ">
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">&quot;games_on_this_platform&quot;:[{&nbsp;&quot;game&quot;:[{&nbsp;&quot;name&quot;:null&nbsp;}]&nbsp;}],</span>
</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; "><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">&quot;name&quot;:&quot;Xbox 360&quot;</span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; ">
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">}]</span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; ">
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; "><br class="webkit-block-placeholder"></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Courier; ">
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; "><span class="Apple-style-span" style="font-family: arial; font-size: 13px; "><div>My PHP script is fairly simple, but it throws up an error &quot;
<span class="Apple-style-span" style="font-family: &#39;Trebuchet MS&#39;; font-size: 16px; "><b><span class="Apple-style-span" style="font-family: arial; "><span class="Apple-style-span" style="font-size: 13px; ">Warning
</span></span></b><span class="Apple-style-span" style="font-size: 10px; "><span class="Apple-style-span" style="font-family: arial; "><span class="Apple-style-span" style="font-size: 13px; ">: Invalid argument supplied for foreach()&quot;, but this only happens on this query. I have other queries I have tested like being able to search for a particular game and that works fine. PHP script below
</span></span><span class="Apple-style-span" style="font-family: arial; font-size: 13px; ">:</span></span></span></div><div><br class="webkit-block-placeholder"></div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">&lt;?php</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; "><br class="webkit-block-placeholder"></span>
</div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">require(&quot;metaweb.class.php&quot;);</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">$count = 0;</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">
$results = array();</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">$mw = new Metaweb();</span></span></div><div>
<span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; "><br class="webkit-block-placeholder"></span></span></div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">$q = array(</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">
&quot;type&quot; =&gt; &quot;/cvg/cvg_platform&quot;,</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">&quot;name&quot; =&gt; &quot;Xbox 360&quot;,
</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">&quot;games_on_this_platform&quot; =&gt; array(&quot;game&quot; =&gt; array(&quot;name&quot; =&gt; null))
</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">);</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; "><br class="webkit-block-placeholder"></span></span></div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">
$auth = &#39;XXXXXXXXXX&#39;;</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; "><br class="webkit-block-placeholder">
</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">$results = $mw-&gt;read($q, $auth);</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; ">
<span class="Apple-style-span" style="font-size: 12px; ">$count = count($results);</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; "><br class="webkit-block-placeholder">
</span></div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; ">?&gt;</span></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; ">
<br class="webkit-block-placeholder"></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; font-size: 12px; "><div>&lt;?php foreach ($results as $game) : ?&gt;</div><div>&nbsp;&nbsp; &nbsp; &lt;li&gt;&lt;?=$game[&#39;name&#39;]?&gt; (&lt;?=$game[&#39;games_on_this_platform&#39;][&#39;game&#39;][&#39;name&#39;]?&gt;)&lt;/li&gt;
</div><div>&lt;?php endforeach; ?&gt;</div></span></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; "><br class="webkit-block-placeholder">
</span></span></div><div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;; "><span class="Apple-style-span" style="font-size: 12px; "><span class="Apple-style-span" style="font-family: arial; font-size: 13px; ">
Any ideas as to why I get results in the query builder but not in PHP, seeing as the query is the same?<br></span></span></span></div><div><br class="webkit-block-placeholder"></div><div>I&#39;ve also mentioned this in the discussions board on freebase but I think it would be good if freebase pages had a link to the MQL query that was used to generate the data on that particular page. For example, this page (
<a href="http://www.freebase.com/view/reorder/topic/en/xbox_360?propertyId=%2Fcvg%2Fcvg_platform%2Fgames_on_this_platform">http://www.freebase.com/view/reorder/topic/en/xbox_360?propertyId=%2Fcvg%2Fcvg_platform%2Fgames_on_this_platform
</a>) does pretty much what I want to do, but has some missing fields etc. It would be good for developers to be able to quickly see how that was generated and would shorten the learning curve dramatically.</div><div><br class="webkit-block-placeholder">
</div><div>Thanks,</div><div>Chris</div><div><br class="webkit-block-placeholder"></div></div></div></div></div></div></span></span></p></div></div>