我的代码使用 php 5.3。我想按以下格式对我的数据进行排序。
01 - 101
号楼 01 - 150 号楼
02 号楼 - 100
号楼 02 号楼 - 105
号楼 03 号楼 - 099 号楼
public static function fetchSortedPropertyUnits() {
$strSql = 'SELECT pu.*,pb.building_name
FROM property_units pu
LEFT JOIN property_buildings pb ON( pu.property_building_id = pb.id )
WHERE pu.management_company_id = ' . $intManagementCompanyId . '
AND pu.property_id = ' . $intPropertyId . '
ORDER BY
COALESCE ( CAST ( SUBSTRING ( pb.building_name FROM \'([a-zA-Z ]{1,26})\' ) AS VARCHAR ), \'\' ),
COALESCE ( CAST ( SUBSTRING ( pb.building_name FROM \'([0-9]{1,10})\' ) AS INTEGER ), 0 ),
COALESCE ( CAST ( SUBSTRING ( pu.unit_number FROM \'([a-zA-Z ]{1,26})\' ) AS VARCHAR ), \'\' ),
COALESCE ( CAST ( SUBSTRING ( pu.unit_number FROM \'([0-9]{1,10})\' ) AS INTEGER ), 0 ),
pb.building_name,
pu.unit_number';
return self::fetchPropertyUnits( $strSql, $objDatabase ); }
这是我使用的 fetch 功能。
&我在我的代码中使用它如下。
$arrobjSortedPropertyUnits = CPropertyUnits::fetchSortedPropertyUnits( $this->m_objPropertyUtilitySetting->getManagementCompanyId(), $this->m_objPropertyUtilitySetting->getPropertyId(), $this->m_objClientDatabase );
foreach( $this->m_arrobjPropertyUnits as $objPropertyUnit ) {
$strUnitNumber = $objPropertyUnit->getUnitNumber();
if( true == valObj( $objPropertyUnit, 'CPropertyUnit' ) && true == $objPropertyUnit->getPropertyBuildingId() ) {
$strUnitNumber = $objPropertyUnit->getBuildingName() . ' - ' . $objPropertyUnit->getUnitNumber();
$objPropertyUnit->setUnitNumber( $strUnitNumber );
}
}
我想按正确的顺序对其进行排序,如果财产没有建筑物,则仅按单元编号对其进行排序。欢迎对此问题提供任何帮助。谢谢。