Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

phRETS query issue

phRETS query issue



6:57 pm on Apr 9, 2012 (gmt 0)

5+ Year Member

Im using phRETS to pull mls data off a RETS server. So far I am able to connect but I am not able to execute a query. This is what I have so far and the notes I was given.

      Offset is not supported.

      The record limit is 50,000

      Use system names (numerical), and not standard names.

      Required to use the Select clause to retrieve only those fields deemed necessary for your application.

      Status is a level 1 required field and must be accompanied with a level 2 search field such as list price= 0+

      Class 4 is the primary class and you need to use Status(79) and one other level 2 field like List Price 0+ (77).

Here is my code

$rets_login_url = "#*$!#*$!X";
$rets_username = " #*$!#*$!X ";
$rets_password = " #*$!#*$!X ";
$rets_user_agent = " #*$!#*$!X ";
$rets_user_agent_password = "useragentpassword";
$rets = new phRETS;
$rets->AddHeader("User-Agent", $rets_user_agent);
$rets->SetParam("offset_support", false);
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password, $rets_user_agent_password);
$search = $rets->SearchQuery("Residential","4","(79=A),(77=1000000)", array('Format' => 'COMPACT', 'QueryType' => 'DMQL'));
// get the first record returned
$listing = $rets->FetchRow($search);
// get list of fields for our loop
$fields = $rets->SearchGetFields($search);
// loop through each field in the response and pull it's value
foreach ($fields as $field) {
echo "+ {$field} value is {$listing[$field]}\n";

This is the error I am getting
Warning: Invalid argument supplied for foreach() in /home/beta/phrets/test.php

Any help that you could provide would be Huge, thank you so much!


9:16 pm on Apr 9, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

You need to do some error handling and check if the SearchGetFields member function returns an array and process it accordingly.

// loop through each field in the response and pull it's value
if( !is_array($fields) ) {
echo '<br />Error: Fields is not an array<br />';
printr $fields;
foreach ($fields as $field) {

It also possible the error manifests when you call the SearchQuery member function. It should return a resource so you could check for errors there too. I don't know the framework so I cannot tell for sure but check if the SearchQuery gets the right arguments.


9:34 pm on Apr 9, 2012 (gmt 0)

5+ Year Member

I just changed

$search = $rets->SearchQuery("Residential","4","(79=A),(77=1000000)", array('Format' => 'COMPACT', 'QueryType' => 'DMQL'));


$search = $rets->SearchQuery("Property","4","(79=A),(77=1000000)", array('Format' => 'COMPACT', 'QueryType' => 'DMQL'));

and now things are working!

Featured Threads

Hot Threads This Week

Hot Threads This Month