我们公司的一个客户的网站除了问题,是房地产公司。我对这个问题的理解是这样的,他们的数据库记录了很多新出的房子套餐,然后通过PHP代码把他们生成XML的文件,但是很多数据库里已经删除的旧的套餐还是会存在于生成出来的XML文件里,不知道问题出在哪里。以下是PHP代码,大家帮我看看,十万火急,谢谢了~~~
<?php
set_time_limit(400);
/*
* This page is developed based on the BHI NHlist - 6.4 XML Data Integration Document September 30, 2009
*/
ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
?><?php //include dbconnect.php
if(file_exists("dbconnect.php")){
include("dbconnect.php");
}//end include dbconnect.php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NHS XML</title>
</head>
<body>
<?phpecho "start time: ". date('Y-m-d H:i:s', time());/* Client requested that the following communities not be included in the feed:
* Highland Chase at Ayersworth, Hamilton View, Lakeside Landings, Myster Ridge
* and these can be found in the communities table. A column 'siteSubmitType'
* has been added but is not in use but could be used in a later iteration
*/$queryBHI="SELECT
l.listingID,
l.stories,
l.beds,
l.baths,
l.halfBaths,
l.price,
l.garage,
l.basement,
l.masterBedroomUpDown,
l.addrZip as 'listZip',
l.addrStreetAddress as 'listStAddr',
l.addrCity as 'listCity',
l.addrCounty as 'listZip',
l.addrState as 'listState',
l.hometype,
c.communityID,
c.communityName,
c.latitude,
c.longitude,
c.address,
c.addrCity,
c.addrState,
c.addrZip,
c.featuredFloorplans,
c.moveSubAmenities,
fp.floorplanID,
fp.name,
fp.active
FROM listings AS l
INNER JOIN communities AS c ON l.communityid = c.communityid, floorplans fp
WHERE
c.siteSubmitType = '1'
AND
(l.hometype = 'S' OR l.hometype = 'P')
AND
fp.floorplanid = l.floorplanid
AND
fp.active = 1
ORDER BY c.communityID ";
//echo $queryBHI;
$resultBHI = mysql_query($queryBHI);
$subcount = mysql_num_rows($resultBHI);$currentDate = date("Ymd");/*builder*/
$builderID = "Corp_4046";
$corpNameSpaces = "Highland Homes";
$corpNameNoSpaces = str_replace(" ", "", $corpNameSpaces);
$corpReportingEmail = "[email protected]";
$corpState = "FL";$BrandLogo="";
$BrandLogo_Med="";
$BrandLogo_Sm="";
$reportingName = $corporateNameSpaces;
$builderWebsite="http://www.highlandhomes.org/";
$tempSubDivisionNumber = 0;//HEADER VAR
$startXML='<?xml version="1.0" encoding="UTF-8"?>
<Builders DateGenerated="'.date('Y-m-d').'T'.date('H:i:s').'">
<Corporation>
<CorporateBuilderNumber>'. $builderID .'</CorporateBuilderNumber>
<CorporateState>'. $corpState .'</CorporateState>
<CorporateName>'. $corpNameSpaces .'</CorporateName>
<Builder>
<BuilderNumber>4046</BuilderNumber>
<BrandName>'. $corpNameSpaces .'</BrandName>
<ReportingName>'. $corpNameSpaces .'</ReportingName>
<DefaultLeadsEmail LeadsPerMessage="All">'. $corpReportingEmail .'</DefaultLeadsEmail>
<BuilderWebsite>'. $builderWebsite .'</BuilderWebsite>';//END HEADER VAR//WRITE XML
$fileName = $corpNameNoSpaces .'_'. $builderID .'_'. $currentDate .'.xml';
$displayFileName = $fileName;//ATRIBUTE VALUES
//$num_of_plans=mysql_num_rows($result);
$buildersData="";
while($row = mysql_fetch_array($resultBHI))
{
$subdivisionNumber = $row['communityID'];
$subdivisionName = $row['communityName'];
$subLeadsEmail = $row['salesConsultantEmail'];
$subAttributeShareWithRealtors="0";
$agent = strval($row['saleConsultantName']);
$agentPhone = ($row['salesConsultantPhone']);
$outOfCommunity = "0";
$street1 = strval($row['address']);
$city = strval($row['addrCity']);
$state = strval($row['addrState']);
$zip = strval($row['addrZip']);
$latitudeSalesOffice = strval($row['latitude']);
$longitudeSalesOffice = strval($row['longitude']);
$email = $corpReportingEmail;
$subAmenities = $row['moveSubAmenities'];
$stories = strval($row['stories']);
$baths = strval($row['baths']);
$halfBaths = strval($row['halfBaths']);
$bedrooms = strval($row['beds']);
$listPrice = strval($row['price']);
$listSqft = strval($row['sqft']);
$listStories = strval($row['stories']); $listCity = $row['listCity'];
$listCounty = $row['listCounty'];
$listZip = $row['listZip'];
$listState = $row['listState'];
$listIdentification = $row['listingID'];
$listGarage = trim($row['garage']); if($tempSubDivisionNumber != $subdivisionNumber)
{
if($tempSubDivisionNumber != 0)
{
$buildersData = $buildersData .'
</Subdivision>';
}
//XML BODY
$buildersData = $buildersData .'
<Subdivision>
<SubdivisionNumber>'. $subdivisionNumber .'</SubdivisionNumber>
<SubdivisionName>'. $subdivisionName .'</SubdivisionName>
<MarketingChannel>NewHomeSource</MarketingChannel>
<UseDefaultLeadsEmail>1</UseDefaultLeadsEmail>
<SubLeadsEmail LeadsPerMessage="All" />
<SalesOffice>
<Agent>'. $agent .'</Agent>
<Address OutOfCommunity="0">
<Street1>'. $street1 .'</Street1>
<City>'. $city .'</City>
<State>'. $state .'</State>
<ZIP>'. $zip .'</ZIP>
<Geocode>
<Latitude>'. $latitudeSalesOffice .'</Latitude>
<Longitude>'. $longitudeSalesOffice .'</Longitude>
</Geocode>
</Address>
<Phone>'.
parsePhone($agentPhone)
.'</Phone>
<Email>[email protected]</Email>
</SalesOffice>
<DrivingDirections>'. $drivingDirections .'</DrivingDirections>
'.
getCommunityAmenities($subdivisionNumber)
.'
<SubDescription>'. $subDescription .'</SubDescription>
<SubWebsite>http://www.highlandhomes.org</SubWebsite>
'. getBaseData($subdivisionNumber, $planNumber, $planName, $listIdentification)
.
getHomeSpec($homeType, $listIdentification,$listStAddr,$listCity,$listState,$listZip,$listrice) ;
}
else
{
$buildersData = $buildersData .
getBaseData($subdivisionNumber, $planNumber, $planName, $listIdentification)
.
getHomeSpec($homeType, $listIdentification,$listStAddr,$listCity,$listState,$listZip,$listrice)
;
} $tempSubDivisionNumber = $subdivisionNumber;
}$xmlFooter='
</Subdivision>
<SubsCount>1'. $subcount .'</SubsCount>
</Builder>
</Corporation>
</Builders>';
$completeXmlFile = $startXML . $buildersData . $xmlFooter;$newXML=fopen($fileName, 'w');
if(fwrite($newXML, $completeXmlFile)){
fclose($newXML);
}else{
echo '<br /> The XML not created!!!';
}
echo "<br>end time: ". date('Y-m-d H:i:s', time());
?>
<br>
<a href="<?php echo $fileName ?>">XML FILE</a> file size: <?php echo filesize($fileName); ?>
</body>
</html><?phpfunction getBaseData($commNum, $planNum, $planName, $listID)
{
$planBaseXML = "";
$fpBaseDataQuery = "select distinct
c.communityid, fp.floorplanid, l.hometype, fp.name as 'floorplan_name', fp.livingArea as 'base_sqft',
min(l.price) as 'min_price', min(l.baths) as 'min_baths', min(l.halfbaths) as 'min_halfbaths',
min(l.beds) as 'min_beds'
from
listings l, floorplans fp, communities c
where
c.communityid = ". $commNum ."
AND
fp.floorplanid = ". $planNum ."
AND
c.communityid = l.communityid
and
l.floorplanid = fp.floorplanid
and
fp.active = 1
group by l.hometype, fp.floorplanid"; $resultFpBaseData = mysql_query($fpBaseDataQuery);
while($fpBDrow = mysql_fetch_array($resultFpBaseData))
{ $listGarage = trim($fpBDrow['garage']); if($listGarage == "" || $listGarage == NULL)
{
$listGarage = 2;
} $planBaseXML = $planBaseXML ."
<Plan Type='SingleFamily'>
<PlanNumber>". $planNum ."</PlanNumber>
<PlanName>".$planName ."</PlanName>
<BasePrice>". $fpBDrow['min_price'] ."</BasePrice>
<BaseSqft>". $fpBDrow['base_sqft'] ."</BaseSqft>
<Baths>". $fpBDrow['min_baths']."</Baths>
<HalfBaths>". $fpBDrow['min_halfbaths'] ."</HalfBaths>
<Bedrooms>". $fpBDrow['min_beds'] ."</Bedrooms>
<Garage>". $listGarage ."</Garage>
".
getImages($listID, "P") ."
</Plan>";
}
return $planBaseXML;
}function getHomeSpec($homeType, $listID,$listStAddr,$listCity,$listState,$listZip,$listrice)
{
if($homeType == "S")
{
$specXML = "
<Spec Type='SingleFamily'>
<SpecNumber></SpecNumber>
<SpecAddress>
<SpecStreet1>". $listStAddr ."</SpecStreet1>
<SpecCity>". $listCity ."</SpecCity>
<SpecState>". $listState ."</SpecState>
<SpecZIP>". $listZip ."</SpecZIP>
</SpecAddress>
<SpecPrice>". $listrice ."</SpecPrice>".
getImages($listID, "S")
."</Spec>";
}
else
{
$specXML = "";
}
return $specXML;
}//$htype = hometype S or P
/*
* the parsePhone function assumes that the salesConsultantPhone field uses hyphens
* as that's all that existed in the database at the time this was created
*/
function parsePhone($phone)
{
$phonePieces = explode("-", $phone);
$phoneXML = "
<AreaCode>". $phonePieces[0] ."</AreaCode>
<Prefix>". $phonePieces[1] ."</Prefix>
<Suffix>". $phonePieces[2] ."</Suffix>
";
return $phoneXML;
}?>
<?php
set_time_limit(400);
/*
* This page is developed based on the BHI NHlist - 6.4 XML Data Integration Document September 30, 2009
*/
ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
?><?php //include dbconnect.php
if(file_exists("dbconnect.php")){
include("dbconnect.php");
}//end include dbconnect.php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NHS XML</title>
</head>
<body>
<?phpecho "start time: ". date('Y-m-d H:i:s', time());/* Client requested that the following communities not be included in the feed:
* Highland Chase at Ayersworth, Hamilton View, Lakeside Landings, Myster Ridge
* and these can be found in the communities table. A column 'siteSubmitType'
* has been added but is not in use but could be used in a later iteration
*/$queryBHI="SELECT
l.listingID,
l.stories,
l.beds,
l.baths,
l.halfBaths,
l.price,
l.garage,
l.basement,
l.masterBedroomUpDown,
l.addrZip as 'listZip',
l.addrStreetAddress as 'listStAddr',
l.addrCity as 'listCity',
l.addrCounty as 'listZip',
l.addrState as 'listState',
l.hometype,
c.communityID,
c.communityName,
c.latitude,
c.longitude,
c.address,
c.addrCity,
c.addrState,
c.addrZip,
c.featuredFloorplans,
c.moveSubAmenities,
fp.floorplanID,
fp.name,
fp.active
FROM listings AS l
INNER JOIN communities AS c ON l.communityid = c.communityid, floorplans fp
WHERE
c.siteSubmitType = '1'
AND
(l.hometype = 'S' OR l.hometype = 'P')
AND
fp.floorplanid = l.floorplanid
AND
fp.active = 1
ORDER BY c.communityID ";
//echo $queryBHI;
$resultBHI = mysql_query($queryBHI);
$subcount = mysql_num_rows($resultBHI);$currentDate = date("Ymd");/*builder*/
$builderID = "Corp_4046";
$corpNameSpaces = "Highland Homes";
$corpNameNoSpaces = str_replace(" ", "", $corpNameSpaces);
$corpReportingEmail = "[email protected]";
$corpState = "FL";$BrandLogo="";
$BrandLogo_Med="";
$BrandLogo_Sm="";
$reportingName = $corporateNameSpaces;
$builderWebsite="http://www.highlandhomes.org/";
$tempSubDivisionNumber = 0;//HEADER VAR
$startXML='<?xml version="1.0" encoding="UTF-8"?>
<Builders DateGenerated="'.date('Y-m-d').'T'.date('H:i:s').'">
<Corporation>
<CorporateBuilderNumber>'. $builderID .'</CorporateBuilderNumber>
<CorporateState>'. $corpState .'</CorporateState>
<CorporateName>'. $corpNameSpaces .'</CorporateName>
<Builder>
<BuilderNumber>4046</BuilderNumber>
<BrandName>'. $corpNameSpaces .'</BrandName>
<ReportingName>'. $corpNameSpaces .'</ReportingName>
<DefaultLeadsEmail LeadsPerMessage="All">'. $corpReportingEmail .'</DefaultLeadsEmail>
<BuilderWebsite>'. $builderWebsite .'</BuilderWebsite>';//END HEADER VAR//WRITE XML
$fileName = $corpNameNoSpaces .'_'. $builderID .'_'. $currentDate .'.xml';
$displayFileName = $fileName;//ATRIBUTE VALUES
//$num_of_plans=mysql_num_rows($result);
$buildersData="";
while($row = mysql_fetch_array($resultBHI))
{
$subdivisionNumber = $row['communityID'];
$subdivisionName = $row['communityName'];
$subLeadsEmail = $row['salesConsultantEmail'];
$subAttributeShareWithRealtors="0";
$agent = strval($row['saleConsultantName']);
$agentPhone = ($row['salesConsultantPhone']);
$outOfCommunity = "0";
$street1 = strval($row['address']);
$city = strval($row['addrCity']);
$state = strval($row['addrState']);
$zip = strval($row['addrZip']);
$latitudeSalesOffice = strval($row['latitude']);
$longitudeSalesOffice = strval($row['longitude']);
$email = $corpReportingEmail;
$subAmenities = $row['moveSubAmenities'];
$stories = strval($row['stories']);
$baths = strval($row['baths']);
$halfBaths = strval($row['halfBaths']);
$bedrooms = strval($row['beds']);
$listPrice = strval($row['price']);
$listSqft = strval($row['sqft']);
$listStories = strval($row['stories']); $listCity = $row['listCity'];
$listCounty = $row['listCounty'];
$listZip = $row['listZip'];
$listState = $row['listState'];
$listIdentification = $row['listingID'];
$listGarage = trim($row['garage']); if($tempSubDivisionNumber != $subdivisionNumber)
{
if($tempSubDivisionNumber != 0)
{
$buildersData = $buildersData .'
</Subdivision>';
}
//XML BODY
$buildersData = $buildersData .'
<Subdivision>
<SubdivisionNumber>'. $subdivisionNumber .'</SubdivisionNumber>
<SubdivisionName>'. $subdivisionName .'</SubdivisionName>
<MarketingChannel>NewHomeSource</MarketingChannel>
<UseDefaultLeadsEmail>1</UseDefaultLeadsEmail>
<SubLeadsEmail LeadsPerMessage="All" />
<SalesOffice>
<Agent>'. $agent .'</Agent>
<Address OutOfCommunity="0">
<Street1>'. $street1 .'</Street1>
<City>'. $city .'</City>
<State>'. $state .'</State>
<ZIP>'. $zip .'</ZIP>
<Geocode>
<Latitude>'. $latitudeSalesOffice .'</Latitude>
<Longitude>'. $longitudeSalesOffice .'</Longitude>
</Geocode>
</Address>
<Phone>'.
parsePhone($agentPhone)
.'</Phone>
<Email>[email protected]</Email>
</SalesOffice>
<DrivingDirections>'. $drivingDirections .'</DrivingDirections>
'.
getCommunityAmenities($subdivisionNumber)
.'
<SubDescription>'. $subDescription .'</SubDescription>
<SubWebsite>http://www.highlandhomes.org</SubWebsite>
'. getBaseData($subdivisionNumber, $planNumber, $planName, $listIdentification)
.
getHomeSpec($homeType, $listIdentification,$listStAddr,$listCity,$listState,$listZip,$listrice) ;
}
else
{
$buildersData = $buildersData .
getBaseData($subdivisionNumber, $planNumber, $planName, $listIdentification)
.
getHomeSpec($homeType, $listIdentification,$listStAddr,$listCity,$listState,$listZip,$listrice)
;
} $tempSubDivisionNumber = $subdivisionNumber;
}$xmlFooter='
</Subdivision>
<SubsCount>1'. $subcount .'</SubsCount>
</Builder>
</Corporation>
</Builders>';
$completeXmlFile = $startXML . $buildersData . $xmlFooter;$newXML=fopen($fileName, 'w');
if(fwrite($newXML, $completeXmlFile)){
fclose($newXML);
}else{
echo '<br /> The XML not created!!!';
}
echo "<br>end time: ". date('Y-m-d H:i:s', time());
?>
<br>
<a href="<?php echo $fileName ?>">XML FILE</a> file size: <?php echo filesize($fileName); ?>
</body>
</html><?phpfunction getBaseData($commNum, $planNum, $planName, $listID)
{
$planBaseXML = "";
$fpBaseDataQuery = "select distinct
c.communityid, fp.floorplanid, l.hometype, fp.name as 'floorplan_name', fp.livingArea as 'base_sqft',
min(l.price) as 'min_price', min(l.baths) as 'min_baths', min(l.halfbaths) as 'min_halfbaths',
min(l.beds) as 'min_beds'
from
listings l, floorplans fp, communities c
where
c.communityid = ". $commNum ."
AND
fp.floorplanid = ". $planNum ."
AND
c.communityid = l.communityid
and
l.floorplanid = fp.floorplanid
and
fp.active = 1
group by l.hometype, fp.floorplanid"; $resultFpBaseData = mysql_query($fpBaseDataQuery);
while($fpBDrow = mysql_fetch_array($resultFpBaseData))
{ $listGarage = trim($fpBDrow['garage']); if($listGarage == "" || $listGarage == NULL)
{
$listGarage = 2;
} $planBaseXML = $planBaseXML ."
<Plan Type='SingleFamily'>
<PlanNumber>". $planNum ."</PlanNumber>
<PlanName>".$planName ."</PlanName>
<BasePrice>". $fpBDrow['min_price'] ."</BasePrice>
<BaseSqft>". $fpBDrow['base_sqft'] ."</BaseSqft>
<Baths>". $fpBDrow['min_baths']."</Baths>
<HalfBaths>". $fpBDrow['min_halfbaths'] ."</HalfBaths>
<Bedrooms>". $fpBDrow['min_beds'] ."</Bedrooms>
<Garage>". $listGarage ."</Garage>
".
getImages($listID, "P") ."
</Plan>";
}
return $planBaseXML;
}function getHomeSpec($homeType, $listID,$listStAddr,$listCity,$listState,$listZip,$listrice)
{
if($homeType == "S")
{
$specXML = "
<Spec Type='SingleFamily'>
<SpecNumber></SpecNumber>
<SpecAddress>
<SpecStreet1>". $listStAddr ."</SpecStreet1>
<SpecCity>". $listCity ."</SpecCity>
<SpecState>". $listState ."</SpecState>
<SpecZIP>". $listZip ."</SpecZIP>
</SpecAddress>
<SpecPrice>". $listrice ."</SpecPrice>".
getImages($listID, "S")
."</Spec>";
}
else
{
$specXML = "";
}
return $specXML;
}//$htype = hometype S or P
/*
* the parsePhone function assumes that the salesConsultantPhone field uses hyphens
* as that's all that existed in the database at the time this was created
*/
function parsePhone($phone)
{
$phonePieces = explode("-", $phone);
$phoneXML = "
<AreaCode>". $phonePieces[0] ."</AreaCode>
<Prefix>". $phonePieces[1] ."</Prefix>
<Suffix>". $phonePieces[2] ."</Suffix>
";
return $phoneXML;
}?>
解决方案 »
- php webservice 传递数组和返回数组的问题
- 请指教一个基础问题:转换日期
- Warning: Smarty error: unable to read resource: "" in /var/vhost/zsti/www/lib/Sm
- 新手:简单的查看数据库记录问题
- 连接mysql 数据库端口问题
- oauth新浪微博模板制作~搜狐微博~ 无法发送图片微博~求救!~
- 2010年 新年 期间 有朋友做php兼职吗?(最好人在广州)
- 怎么编译php_memcache.dll
- PHP 的汉字编码问题,4个小实验。询问原因?
- 如何限制同样内容的信息,一天只能发布一次?
- php操作XML向已经存在的节点添加属性并赋值 怎么操作?
- EasyEclipse for PHP怎么调试PHP程序
c.siteSubmitType = '1' and c.删除标识 <> 已经删除