Can't get results from SearchQuery() in phrets

2019-05-22 20:21发布

问题:

I can't seem to get the SearchQuery() function in phrets to return anything. I know my Resouce and Class. I also know the sysid of the field name I'm using in the query.

Here is my code

<?php @include_once('login.php'); ?>
<pre>
<?php

$rets = new PHRETS;

$rets->AddHeader("User-Agent", $rets_user_agent);
/* Connect */
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password, $rets_user_agent_password);

if($connect) {

    /*resources*/
    $resources = $rets->GetMetadataResources();
foreach ($resources as $resource) {
        echo "+ Resource {$resource['ResourceID']} described as " . $resource['Description'] . "\n";
}

    /*get classes*/
    $classes = $rets->GetMetadataClasses("Property");
foreach ($classes as $class) {
        echo "+ Class {$class['ClassName']} described as " . $class['Description'] . "\n";
}

    /*get fields*/
    $fields = $rets->GetMetadataTable("Property", 1);
print_r ($fields);

    /* Search RETS server */
$search = $rets->SearchQuery("Property",1,"(135=2013-01-01+)");
while ($listing = $rets->FetchRow($search)) {
   echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
   echo "{$listing['City']}, ";
   echo "{$listing['State']} {$listing['ZipCode']} listed for ";
   echo "\$".number_format($listing['ListPrice'])."\n";
}





    $rets->FreeResult($search);
    $rets->Disconnect();
} else {
    $error = $rets->Error();
    print_r($error);
}



?>
</pre>

I used the GetMetadataResources() and GetMetadataClasses() to get the resource name and property names. I used GetMetadataTable("Property", 1) to get the sysid of the fields. I use the sysid for 'ListDate' to use in my query. I must be doing something wrong.

You can see the live page here http://miamiheatfan.com/phrets/example5.php

Thanks

回答1:

The second parameter in the search query is a string, not an integer. From the PHRETS specification: https://github.com/troydavisson/PHRETS/wiki/SearchQuery

Change your query from:

 $search = $rets->SearchQuery("Property",1,"(135=2013-01-01+)");

to:

$search = $rets->SearchQuery("Property","1","(135=2013-01-01+)");

If that doesn't work, try using the Standard Name of "ListDate" instead of the System Name of "135":

$search = $rets->SearchQuery("Property","1","(ListDate=2013-01-01+)");


标签: php rets