[Developers] wildcard search in PHP

will will at metaweb.com
Tue May 15 17:05:40 UTC 2007


hi peter,

i don't think the problem is with null value in php. when you're making
a wildcard query you'll get back a list of bands. this means you'll need
to add an array on the outside to hold the list. you'll also have to
traverse the array differently than in the example by first iterating
over each band found, and then iterate over each album by the band.

try something like:

   // Build a MQL request for the list of albums by a list of band
   $query = array(array("type" => "/music/artist",
                        "name" => null,
                        "name~=" => "^$band*",
                        "album" => array()));

   // Insert your own freebase.com cookie data into the string below
   $credentials = 'metaweb-user=YOUR_METAWEB-USER_COOKIE_HERE';

   // Submit the query using the utility function defined earlier
   $result = $metaweb->read($query, $credentials);

   // iterate over each band found
   foreach ($result as $item) {
     echo "band: " . $item["name"] . "<br>";
     $albums = $item["album"];
     // iterate over each album of a band
     foreach ($albums as $album) echo "<li>" . $album . "</li><br>";
   }

will

Peter Boot wrote:
> I am trying to extend the example code albumlist.php to perform a
> wildcard search. The query array, shown below,  that works in the
> Query Editor does not work in PHP. The $response["qname"]["status"]
> variable in metaweb.php is ./mql/status/error' .
> 
> $query = array("type" => "/music/artist",
> "name" => null ,
> "name~=" => "^" . $band . "*" );
> 
> Can some one please tell me what I am doing wrong ?
> 
> thanks
> 
> Peter



More information about the Developers mailing list