I am using this php script to get the result from a simple search query documented here
And I have downloaded this excel file of metadata of property here
$rets_login_url = "http://sef.rets.interealty.com/Login.asmx/Login";
$rets_username = "xxxxxxxx";
$rets_password = "xxxxxxxx";
$rets_user_agent = "PHRETS/1.0";
$rets_user_agent_password = "xxxxxxx";
//////////////////////////////
// start rets connection
$rets = new phRETS;
// Uncomment and change the following if you're connecting
// to a server that supports a version other than RETS 1.5
$rets->AddHeader("RETS-Version", "RETS/1.5");
$rets->AddHeader("User-Agent", $rets_user_agent);
echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password, $rets_user_agent_password);
// check for errors
if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-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);
echo "+ Disconnecting<br>\n";
$rets->Disconnect();
when I run this script it shows the result connected and then disconnected. But no result is found. I tried many things suggested on some questions for which result was not showing, But nothing is working for me. Where I am wrong?
My RETS server information are here:
RETS Server: SEF RETS System
RETS System ID: SEFRETS
Login URL: http://sef.rets.interealty.com:80/Login.asmx/Login
RETS Version: 1.5
Server Software: Microsoft-IIS/6.0
I also could not understand what is $rets_modtimestamp_field = "LIST_87";
Please Help me. I need some suggestion over how to get data from the RETS.
The issue is with the parameters in your SearchQuery.
One of the fields in your search query is ListDate. Looking at the attached excel file containing the metadata, "ListDate" is in Column B under StandardNames. The RETS specification uses System Names as default (see below). You need to specify '"StandardNames" => 1' in the options parameter in the SearchQuery function:
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-01-01+)",array("StandardNames" => 1));
Also, check to make sure the second argument, class, of your SearchQuery is correct. To do this you could use the GetMetadataClasses function in PHRETS.
You could also use retsmd.com by logging in with your RETS Server url, username, and password.
The $rets_modtimestamp_field is the field which is a datetime value indicating the date and time when a listing was last modified.
In section 7.4.7 in the RETS 1.7.2 Specification document, http://www.reso.org/assets/RETS/Specifications/rets_1_7_2.pdf,
"Queries may use either standard names or system names in the query (Section 7.7). If the
client chooses to use standard names, it MUST indicate this using the StandardNames
argument...If this entry is set to ("0") or is not present the field names passed in the search are the
SystemNames, as defined in the metadata."
To address your last comment, you need to specify ListingStatus as well, as it is also a required field when running a query. The lookup values for ListingStatus are:
A = Active-Available
B = Backup Contract-Call LA
C = Cancelled
CS = Closed Sale
PS = Pending Sale/Rental
Q = Terminated
T = Temp Off Market
W = Withdrawn
X = Expired
So try something like this instead:
$query ="(922=MIAMI),(246=A)";
Or if you're using standard names:
$query ="(City=MIAMI),(ListingStatus=A)";
And finally:
$search = $rets->SearchQuery("Property", $class, $query, array("StandardNames" => 1, 'Limit' => 10, ));
This should allow you to get some results back at least. Beyond that you can just tweak your query until you get the results you want.
Related
I'm having a problem with the query it works fine in SQL server but when I trying to return the row in PHP it comes back without any results. See the code below the issue is with this field SO_SalesOrderHistoryDetail.ItemCodeDesc this field is exactly what it sounds like it's an item description and on this particular record it has this data in it. ACC, Smart-Trek™ Deluxe Stereo
I have confirmed this is the issue ™ for some reason this field will not display in PHP. I could edit the data although I would like to reserved that option for a last ditch effort. I'm not sure why this particular data is stopping all information from being returned. I don't get a PHP error. Any help would be most welcome much appreciated.
$tsql = "
SELECT
SO_SalesOrderHistoryHeader.CustomerNo,
SO_SalesOrderHistoryHeader.CustomerPONo,
SO_SalesOrderHistoryDetail.SalesOrderNo,
SO_SalesOrderHistoryDetail.CancelledLine,
SO_SalesOrderHistoryDetail.ItemCode,
SO_SalesOrderHistoryDetail.ItemCodeDesc,
SO_SalesOrderHistoryDetail.QuantityBackordered,
SO_SalesOrderHistoryDetail.QuantityOrderedRevised,
SO_SalesOrderHistoryDetail.PurchaseOrderNo,
SO_SalesOrderHistoryDetail.QuantityShipped,
SO_SalesOrderHistoryHeader.OrderStatus,
SO_SalesOrderHistoryHeader.OrderDate,
SO_SalesOrderHistoryHeader.CustomerPONo
FROM SO_SalesOrderHistoryDetail
INNER JOIN SO_SalesOrderHistoryHeader ON
SO_SalesOrderHistoryDetail.SalesOrderNo = SO_SalesOrderHistoryHeader.SalesOrderNo
WHERE
(SO_SalesOrderHistoryHeader.CustomerNo = 'XXXXXXX') AND
(SO_SalesOrderHistoryHeader.OrderStatus <> 'X') AND
(SO_SalesOrderHistoryDetail.CancelledLine = 'N') AND
(SO_SalesOrderHistoryHeader.CustomerPONo = 'XXXXXXX')
";
$getResults= sqlsrv_query($connms, $tsql);
$row = sqlsrv_fetch_array($getResults);
I found the answer I thought I'd pass it along to help others. It can be found at the URL below.
Add this for your connection configuration array: "CharacterSet" =>"UTF-8".
For example:
$connectionInfo = array( "Database"=>"DBName", "CharacterSet" =>"UTF-8" );
https://learn.microsoft.com/en-us/archive/blogs/brian_swan/sql-server-driver-for-php-connection-options-characterset
I've been trying to update my data according to the user session (UserLogin) but it kept saying: Data type mismatch in criteria expression. The print_r is just for testing purposes.
Thanks in advance,
Z
function Employee1_BeforeShow(& $sender)
{
$Employee1_BeforeShow = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $Employee1; //Compatibility
$Page = CCGetParentPage($sender);
$db = $Page->Connections["PettyCashMDB"];
$sql1 = "UPDATE Employee SET Employee.LastActive = Date() WHERE Employee.[EmpID] = ". $_SESSION['UserLogin'];
$db->query($sql1);
print_r($_SESSION['UserLogin']);
$db->close();
Employee1_BeforeShow #67-67106FAD
return $Employee1_BeforeShow;
}
EDIT: I've tried #NanaPartykar 's method and by accident I've noticed that it does get the value from $_SESSION['UserLogin'], just that somehow the datatype is different.
EDIT: It displays the error Data type mismatch but both of them are string and returns string.
Instead of Employee.[EmpID], use Employee.EmpID
You need some quotes:
$sql1 = "UPDATE Employee SET Employee.LastActive = Date() WHERE Employee.[EmpID] = \'". $_SESSION['UserLogin'] . "\'";
Z - There are a bunch of built-in Codecharge functions to assist with getting values from querystring, sessions and controls.
eg: CCGetSession("UserLogin", "default");
http://docs.codecharge.com/studio50/html/index.html?http://docs.codecharge.com/studio50/html/Components/Functions/PHP/Overview.html
and executing SQL with some validating (from 'Execute Custom SQL' help topic):
$db = new clsDBConnection1();
$SQL = "INSERT INTO report (report_task_id,report_creator) ".
"VALUES (". $db->ToSQL(CCGetFromGet("task_id",0),ccsInteger) .",". $db->ToSQL(CCGetUserID(),ccsInteger) .")";
$db->query($SQL);
$db->close();
The $db->ToSQL (and CCToSQL) functions convert and add quotes for relevant data types (ccsText, ccsDate).
There are many examples in the Manual under 'Examples' and 'Programming Reference' for PHP (and ASP, .NET, etc)
http://support.codecharge.com/tutorials.asp
I strongly suggest looking at some of the examples, as Codecharge will handle a lot of the 'plumbing' and adding a lot of custom code will causing problems with the generation of code. In your example, you should add a 'Custom Code' action to the Record's 'Before Show' Event and add your code there. If you add code just anywhere, the entire section of code (eg: Before Show) will change colour and no longer be updated if you change something.
For example, if you manually edited the 'Update' function to change a default value, then no changes through the IDE/Properties will change the 'Update' function (such as adding a new field to the Record).
Finally got it to work, this is the code $sql1 = "UPDATE Employee SET LastActive = Date() WHERE EmpID = '$_SESSION[UserLogin]' "; Thanks to everyone that helped out.
I am trying to display data from a MySQL database table using the native joomla PHP objects, however I can never get it to work right. It never displays any data.
I know how to display the data by connecting to the database the old fashion way, like below...
$con = mysqli_connect("localhost","xxxxxx_user10","$dbpass","xxxxxxx_final");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
//What is the base model
$sku = $finish;
// Select The Correct Table
$result = mysqli_query($con,"SELECT * FROM BAH_finish WHERE color_value='$sku' GROUP BY uniqueID ORDER BY uniqueID ASC");
$row = mysqli_fetch_array($result);
$finishname = $row['color_name'];
$finishtype = $row['color_type'];
However i'd like to display content like I have above, but by using the joomla native php objects, so iv'e created a sample php table with the following fields.....
| ID | Last | First | Address | City | State | ZIP
and tried to display it (ALL ROWS) / OR (ONE ROW) using the following joomla code.....but nothing happens....no matter how I try to switch it up or change out parts of the code....So my thinking is that i'm missing a fundamental part of how this should work....Thanks again for your help! Also please do not quote joomla 2.5 component tutorial from joomla.org...that is where I've gotten this code and IMO it lacks a lot of information.
<?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('Last', 'First', 'Address', 'City', 'State', 'ZIP')));
$query->from($db->quoteName('111testnames'));
$query->where($db->quoteName('Last') . $db->quote('buffet'));
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
echo $results;
?>
You have to correct: $query->from($db->quoteName('111testnames'));
to $query->from($db->quoteName('#__111testnames'));
using #__ automatically adds the suffix of your table.
Another error that I could see is the where clause doesn't have have an operator. Please try to correct it to $query->where($db->quoteName('Last') ." = ". $db->quote('buffet'));.
In order to have a proper view of the results you have to use print_r($results); instead of echo $results; as there is an object array you have to display not a string.
Good Luck!
I got an SQL error message when activating a rule with some Php validation.
The goal of that rule is to check if a user has voted more than 2 times in the last 24 hours.
Here is the code I used:
// Configure your settings:
$daily_limit = 2;
$content_type = 'node';
$day = strtotime(date('Y-m-d'))-1;
// Load the active user account
global $user;
// Drupal has a security feature called the Database Abstraction Layer.
// You have to build DB queries with variables that are defined in an array.
// Define the query string, where ":drupaluid" etc. are arbitrary placeholders
$query = 'SELECT * FROM votingapi_vote WHERE uid=:drupaluid AND content_type=:drupaltype AND timestamp > :day';
// Define each placeholder
$variables = array(':drupaluid' => $user->uid, ':drupaltype' => $content_type, ':day' => $day);
// Query the Drupal database
$result = db_query($query, $variables);
// Count the number of rows returned from the Drupal database
// From: http://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query/7
$nodecount = $result->rowCount();
// Set the flag as to whether this Rule is effective or not
if ( $nodecount >= $daily_limit) {
return TRUE; // You will be over the accepted quota
} else {
return FALSE; // Still got room. Allow the new node.
}
I tried to debug the query but even a simple query like $query = 'SELECT * FROM votingapi_vote WHERE uid = 1 is not working in Php whereas It work in mysql console.
Does anyone see this error?
DatabaseStatementInterface::rowCount specifically returns
The number of rows affected by the last DELETE, INSERT, or UPDATE statement executed.
It's not used to retrieve the count of a result set. To do that use a count query, or simply use PHP functions
$result = db_query($query, $variables)->fetchAll();
$nodecount = count($result);
Hey, I am wondering how to extract the data from a table in a database onto a table in a page (users.php),
For example:
I want to be able to get all of the usernames and all the id's from my database onto a table.
So if I have in my database:
1 - Fred
2 - Frank
3 - Margret
It will see that I have them user's and id's in the database and print them onto a table.
Any help would be great,
Thanks.
Connect to your database. Host is the location, like localhost if its on your computer, or on the same server as your code. User and Password are self explanatory.
mysql_connect("host", "user", "pass");
The name of the database you want to access.
mysql_select_db("database");
The actual mysql query.
$result = mysql_query('SELECT `User_Name`, `User_ID` FROM TABLE');
Sort it into an array
while($temp = mysql_fetch_array($result)
{
$id = $temp['User_ID'];
$array[$id]['User_ID'] = $id;
$array[$id]['User_Name'] = $temp['User_Name'];
}
Turn the array into a table. (You could skip the last step and go right to this one.
$html ='<table><tr><td>User ID</td><td>User Name</td></tr>';
foreach($array as $id => $info)
{
$html .= '<tr><td>'.$info['User_ID'].'</td><td>'.$info['User_Name'].'</td></tr>';
}
echo $html . '</table>';
Or, the formatting you wanted
$html ='User Id - User Name';
foreach($array as $id => $info)
{
$html .= $info['User_ID'].' - '.$info['User_Name'].'<br>';
}
echo $html;
(For this answer, I will use the mysqli extension -- you could also want to use PDO ;; note that the mysql extension is old and should not be used for new applications)
You first have to connect to your database, using mysqli_connect (And you should test if the connection worked, with mysqli_connect_errno and/or mysqli_connect_error).
Then, you'll have to specifiy with which database you want to work, with mysqli_select_db.
Now, you can send an SQL query that will select all data from your users, with mysqli_query (And you can check for errors with mysqli_error and/or mysqli_errno).
That SQL query will most likely look like something like this :
select id, name
from your_user_table
order by name
And, now, you can fetch the data, using something like mysqli_fetch_assoc -- or some other function that works the same way, but can fetch data in some other form.
Once you have fetched your data, you can use them -- for instance, for display.
Read the pages of the manual I linked to : many of them include examples, that will allow you to learn more, especially about the way those functions should be used ;-)
For instance, there is a complete example on the page of mysqli_fetch_assoc, that does exactly what you want -- with countries insteand of users, but the idea is quite the same ^^
You can do something like the following (using the built-in PHP MySQL functions):
// assuming here you have already connected to the database
$query = "SELECT id,username FROM users";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result))
{
print $row["id"] . " - " . $row["username"] . "\n";
}
which will give you (for example):
1 - Fred
2 - Frank
3 - Margret
Where I've put the print statement, you can do whatever you feel like there eg put it into a table using standard HTML etc.