0

Using this mysql/php conversion to mysqli question. I was able to formulate an edit to my own script. When I run this script I get no records although I know I have records produced when I query the DB directly. What am I missing?

    <?php
error_reporting(E_ALL); 
ini_set('display_errors', 1);
$file = 'matrix_swfl_res';

// connecting to database
//$connect = @mysql_connect($host.':'.$port, $user, $pass)or die (@mysql_error());

$connect = mysqli_connect( 'IP', 'User', 'Password', 'database', '3306')or die (@mysqli_error());

// selecting database
//@mysql_select_db($db,$connect) or die (@mysql_error());

header("Content-Type: text/xml;charset=UTF-8");
echo '<?xml version="1.0" encoding="UTF-8"?>
<Properties>';

// selecting data from "matrix combined"
$query = @mysqli_query("SELECT Acres, ActiveOpenHouseCount, AdditionalRooms, Amenities, AmenityRecFee, AmenRecFreq, ApartmentNumber, ApplicationFee, Approval, ApproxLivingArea, AssociationMngmtPhone, BathsFull, BathsHalf, BathsTotal, BedroomDesc, Bedrooms, BedsTotal, Block, BloggingYN, BoatAccess, BuilderProductYN, BuildingDesc, BuildingDesign, BuildingNumber, CableAvailableYN, CanalWidth, CarportDesc, CarportSpaces, CDOM, City, CloseDate, ClosePrice, CoListAgent_MUI, CoListAgentFullName, CoListOffice_MUI, CoListOfficeMLSID, CoListOfficeName, CoListOfficePhone, CommunityType, ConditionalDate, CondoFee, CondoFeeFreq, Construction, Cooling, CountyOrParish, CreatedDate, CurrentPrice, Development, DevelopmentName, DiningDescription, DOM, ElementarySchool, Elevator, Equipment, ExteriorFeatures, ExteriorFinish, Flooring, FloorPlanType, ForeclosedREOYN, FullAddress, FurnishedDesc, GarageDesc, GarageDimension, GarageSpaces, GuestHouseDesc, GuestHouseLivingArea, GulfAccessType, GulfAccessYN, Heat, HighSchool, HOADesc, HOAFee, HOAFeeFreq, InteriorFeatures, InternetSites, Irrigation, KitchenDescription, LandLeaseFee, LandLeaseFeeFreq, LastChangeTimestamp, LastChangeType, LeaseLimitsYN, LeasesPerYear, LegalDesc, LegalUnit, ListAgent_MUI, ListAgentDirectWorkPhone, ListAgentFullName, ListAgentMLSID, ListingOnInternetYN, ListOffice_MUI, ListOfficeMLSID, ListOfficeName, ListOfficePhone, ListPrice, LotBack, LotDesc, LotFrontage, LotLeft, LotRight, LotUnit, Maintenance, Management, MandatoryClubFee, MandatoryClubFeeFreq, MandatoryHOAYN, MasterBathDescription, MasterHOAFee, MasterHOAFeeFreq, Matrix_Unique_ID, MatrixModifiedDT, MiddleSchool, MinDaysofLease, MLS, MLSAreaMajor, MLSNumber, NumberofCeilingFans, OneTimeLandLeaseFee, OneTimeMandatoryClubFee, OneTimeOtheFee, OneTimeRecLeaseFee, OneTimeSpecialAssessmentFee, OriginalListPrice, OwnershipDesc, ParcelNumber, Parking, Pets, PetsLimitMaxNumber, PetsLimitMaxWeight, PetsLimitOther, PhotoCount, PhotoModificationTimestamp, Possession, PostalCode, PostalCodePlus4, PotentialShortSaleYN, PrivatePoolDesc, PrivatePoolYN, PrivateSpaDesc, PrivateSpaYN, PropertyAddressonInternetYN, PropertyInformation, PropertyType, RearExposure, Restrictions, Road, Roof, RoomCount, Section, SellingAgent_MUI, SellingAgentFullName, SellingAgentMLSID, SellingOffice_MUI, SellingOfficeMLSID, SellingOfficeName, SellingOfficePhone, SellPricePerSqFt, Sewer, SourceofMeasureLivingArea, SourceofMeasureLotDimensions, SourceofMeasureLotSize, SourceofMeasureTotalArea, SpecialAssessment, SpecialAssessmentFeeFreq, SpecialInformation, StateOrProvince, Status, StatusType, StormProtection, StreetDirPrefix, StreetDirSuffix, StreetName, StreetNumber, StreetNumberModifier, StreetSuffix, SubCondoName, SubdivisionNumber, TaxDesc, TaxDistrictType, Taxes, TaxYear, TotalArea, TotalFloors, Township, TransferFee, UnitCount, UnitFloor, UnitNumber, UnitsinBuilding, UnitsinComplex, View, VirtualTourURL, Water, WaterfrontDesc, WaterfrontYN, Windows, YearBuilt, ZoningCode, display_address_yn, list_on_internet_yn, Frame, Base, Img, latitude, longitude FROM matrix_swfl_res WHERE ListOfficeName LIKE 'Royal Shell%' AND ListPrice >= 100 AND PhotoCount >= 1");
while($row = @mysqli_fetch_array($query)){
$title = $row['MLSNumber'];
$listing = $row['Matrix_Unique_ID'];
$date = $row['CreatedDate'];
$fulladdress = $row['FullAddress'];
$Unit = $row['UnitNumber'];
$City= $row['City'];
$ZipCode= $row['PostalCode'];
$Latitude= $row['latitude'];
$Longitude= $row['longitude'];
$Community= $row['SubCondoName'];
$price = $row['ListPrice'];
//$description = $row['PropertyInformation'];
$description  = htmlspecialchars($row['PropertyInformation'], ENT_QUOTES, 'utf-8');   
$VisualTourUrl = $row['VirtualTourURL'];
$BedroomNumber = $row['Bedrooms'];
$BathroomNumber = $row['BathsTotal'];
$SqFt = $row['ApproxLivingArea'];
$Agent = $row['ListAgentFullName'];
$Agents = explode(" ", $Agent);
$agentname = explode(" ",$Agent);
$firstname = $agentname[0];
$lastname = array_pop($agentname);
$pic_count = $row['PhotoCount'];
$img = $row['Img'];
$base = $row['Base'];
echo '<Property>';
echo '<Adid>' . $title . '</Adid>';
echo '<Address1>' . $fulladdress . '</Address1>';
echo '<Address2>' . $Unit . '</Address2>';
echo '<City>' . $City . '</City>';
echo '<State>FL</State>';
echo '<Province></Province>';
echo '<Zip>' . $ZipCode . '</Zip>';
echo '<Longitude>' . $Longitude . '</Longitude>';
echo '<Latitude>' . $Latitude . '</Latitude>';
echo '<Region></Region>';
echo '<Community><![CDATA[' . $Community . ']]></Community>';
echo '<Country>USA</Country>';
echo '<Mls>' . $title . '</Mls>';
echo '<ContactData>';
echo '<ContactFirstName>' . $firstname . '</ContactFirstName>';
echo '<ContactLastName>' . $lastname . '</ContactLastName>';
echo '<ContactAgencyName>Royal Shell Real Estate</ContactAgencyName>';
echo '<ContactEmail>wsjInquiry@royalshellrealestate.com</ContactEmail>';
echo '<ContactURL><![CDATA[http://www.royalshellrealestate.com/search-results/?fullinfo=' . $title . ']]></ContactURL>';
echo '</ContactData>';
echo '<Brokerage>Royal Shell Real Estate</Brokerage>';
echo '<PostDate>' . $date . '</PostDate>';
echo '<VisualTourUrl><![CDATA[' . $VisualTourUrl . ']]></VisualTourUrl>';
echo '<OriginalListPrice>' . $price . '</OriginalListPrice>';
echo '<Terms>sell</Terms>';
echo '<MinPrice>' . $price . '</MinPrice>';
echo '<PropertyType>Single Family</PropertyType>';
echo '<BathroomNumber>' . $BathroomNumber . '</BathroomNumber>';
echo '<BedroomNumber>' . $BedroomNumber . '</BedroomNumber>';
echo '<Description><![CDATA[' . $description . ']]></Description>';
echo '<SqFt>' . $SqFt . '</SqFt>';
echo '<Images>';

for( $pic_start=1; $pic_start<=$pic_count; $pic_start++ ){
    echo '<Image><![CDATA[http://www.myagentsbuddy.com/feeds/' . $img . '/rets_images/' . $listing . '_' . $pic_start . '.jpg]]></Image>';
}

echo '</Images>';
echo '</Property>';
}
echo '</Properties>';
?>
Community
  • 1
  • 1
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79
  • [mysqli_query()](http://php.net/manual/en/mysqli.query.php) need first parameter as your connection. And you are hiding your error by putting `@` in front on mysqli function – Saty Apr 14 '17 at 12:23
  • @saty what do you mean? Can you provide an example please? – Rocco The Taco Apr 14 '17 at 12:24
  • 1
    `mysqli_query($connect,"SELECT Acres, ActiveOpenHouseCount,....")// pass first parameter as database connection.` – Saty Apr 14 '17 at 12:26
  • 1
    And get rid of the @ before mysqli_query - it prevents errors from being shown, and is bad practice. Also, that query... how many columns is in that one table? Wouldn't be simpler to just do `SELECT * FROM...`? – junkfoodjunkie Apr 14 '17 at 12:32
  • Thanks guys for the help. @Saty I'll mark the answer for you if you want to put an Answer in? – Rocco The Taco Apr 14 '17 at 12:42

0 Answers0