Condo Unit Listing Tracker

Welcome to the VCI Condo Unit Listing Tracker. This index tracks the number of units currently for sale in a selection of new condo towers in the downtown Vancouver core. Rollover graph image for more information. This index is updated daily.

/*
coded by dmitry@dvinyaninov.com
*/
set_time_limit(0);
error_reporting(E_ALL);

include 'functions.php';
include 'settings.php';
include 'db_open.php';

if( $_GET['update']) {

$buildings = $db->queryAll(‘SELECT * FROM building LIMIT 100′, null, MDB2_FETCHMODE_ASSOC);

if( count($buildings) ) {
foreach($buildings AS $building) {
$bulding_page = getPage($building['url']);
if( preg_match(‘/

]*>(.*)<\/table>/imsU’,$bulding_page,$table) ) {
if( preg_match_all(‘/
(.*)<\/tr>/imsU’,$table[1],$table_listings) ) {
foreach( $table_listings[1] AS $key=>$listing) {
if( $key == 0 ) {
$listing_header = preg_split(‘/ ]*>|<\/th>/ims’,$listing);
foreach($listing_header AS $column) {
$column_name = trim(preg_replace(‘/[^\w]*/’,”,strip_tags(html_entity_decode($column))));
$header[] = strtolower($column_name);
}
}
else {
$listing_values = preg_split(‘/ ]*>|<\/td>/ims’,$listing);
$listing_sql_values = array();
foreach($listing_values AS $key=>$listing_value) {
$listing_sql_values[$header[$key]] = $listing_value;
}

$sql = “REPLACE INTO listing
(building_id, posted, mls, address, style, bed, bath, sqft, maintanance, price)
VALUES(‘”.$building['building_id'].”‘,NOW(),’”.$db->escape($listing_sql_values['mls']).”‘,’”.$db->escape($listing_sql_values['address']).”‘,’”.$db->escape($listing_sql_values['style']).”‘,’”
.$db->escape($listing_sql_values['bed']).”‘,’”.$db->escape($listing_sql_values['bath']).”‘,’”.$db->escape($listing_sql_values['sqft']).”‘,’”.$db->escape($listing_sql_values['maintanance']).”‘,’”
.$db->escape($listing_sql_values['price']).”‘)”;

$result = $db->query($sql);

if ( PEAR::isError( $result ) ) {
var_dump( $result );
}
}
}
}
}
}
}

}

$updated = $db->queryOne(“SELECT MAX(posted) AS updated FROM `listing`”);

$maxpercent = $db->queryOne(“SELECT CONCAT(ROUND(count(*)/(units/100),2)) FROM listing l
INNER JOIN building b USING(building_id)
WHERE posted = ‘$updated’ GROUP BY building_id ORDER BY ROUND(count(*)/(units/100),2) DESC”);

$stats = $db->queryRow(“SELECT count(*) AS for_sale, DATE_FORMAT(posted,’%d/%m/%Y’) AS today, SUM(DISTINCT units) AS total, ROUND(count(*)/(SUM(DISTINCT units)/100),2) AS percent FROM listing l
INNER JOIN building b USING(building_id)
WHERE posted = ‘$updated’”, null, MDB2_FETCHMODE_ASSOC);

$sql = “SELECT name AS ‘building’, url, units AS ‘total’, count(*) AS ‘for_sale’, CONCAT(ROUND(count(*)/(units/100),2),’%') AS percent
, IF(posted = ‘$updated’,'today’,IF(posted = (‘$updated’ – INTERVAL 1 DAY),’yesterday’,'weekago’)) AS posted
FROM listing l
INNER JOIN building b USING(building_id)
WHERE posted IN (‘$updated’,'$updated’ – INTERVAL 1 DAY,’$updated’ – INTERVAL 7 DAY) GROUP BY building_id, posted ORDER BY name, l.posted DESC”;

$items = $db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC);

include ‘db_close.php’;
/*
echo ‘UPDATE

‘;
*/
if( count($items) ) {
/*
echo ‘LAST UPDATED: ‘.$updated.’

‘;

echo ‘

‘;
echo ‘

‘;
*/

$config['height'] = ’200′;
$percent2pixel = $config['height'] / ($maxpercent*1.2);

echo ‘     Current listings as of ‘.$stats['today'].’: ‘.$stats['for_sale'].’ of ‘.$stats['total'].’ existing units(‘.$stats['percent'].’%)

‘;
echo ‘

    ‘;
    $id = 0;
    foreach($items AS $key=>$item) {

    switch ( $item['posted'] ) {

    case “today”:
    $current = $item;
    $table_p1 = ‘

  • ‘;
    $table_p2 = ‘

  • ‘;
    $table_p3 = ‘

  • ‘;
    $yesterday = 0;
    $weekago = 0;
    break;

    case “yesterday”:
    $yesterday = $current['for_sale']-$item['for_sale'];
    break;

    case “weekago”:
    $weekago = $current['for_sale']-$item['for_sale'];

    default:
    echo $table_p1;
    //echo ‘

  • -1?’green”>’:'red”>’).$yesterday.’
  • ‘;
    echo ‘

  • ‘;
    echo ‘

‘;
foreach($items AS $item) {
switch ( $item['posted'] ) {
case “today”:
echo ‘

‘;
break;
default:
}
}
echo ‘

 building   total    for sale   percent 
 ‘.$item['building'].’  ’.$item['total'].’  ’.$item['for_sale'].’  ’.$item['percent'].’

‘;

}
else {
echo ‘no data’;
}

?>

The code for the C.U.L.T. index was donated to the VCI Community by c0der, the same programmer who built the comment rating system used on this site. c0der is a Vancouver based Systems Architect working with Linux, Security, Oracle Fusion and PHP/MySQL technology stacks. If you have a project you’d like him to consult or program for you can email him directly: coder@vancouvercondo.info.

Wordpress theme by Abhishek Tripathi of Mediawick Digital Solutions