function search_apartments($keyword, $sleeps, $page) { error_log("page: {$page}"); $conn = db_connect(); $resultSet = new Property_Dom_ResultSet(); if (!empty($keyword)) { $keyword = '%' . $keyword . '%'; } $limit_count = 30; $limit_start = ($page - 1) * $limit_count; if (empty($keyword)) { $sql = "SELECT * FROM apartments where description like '%Sleeps {$sleeps}%' order by id asc limit {$limit_start}, {$limit_count}"; } else { $sql = "SELECT * FROM apartments where (title like '{$keyword}' OR description2 like '{$keyword}') AND description like '%Sleeps {$sleeps}%' order by id asc limit {$limit_start}, {$limit_count}"; } //echo $sql;die; error_log("Query: " . $sql); $result = mysql_query($sql); $i = 0; while ($row = mysql_fetch_assoc($result)) { $resultSet->addTitleByIndex($i, html_entity_decode($row['title'])); $resultSet->addDescriptionByIndex($i, html_entity_decode($row['description'])); $resultSet->addDescriptionByIndex($i, $row['description2']); $resultSet->addPropertyImageLinkByIndex($i, $row['thumb_url']); $resultSet->addPropertyDetailLinkByIndex($i, $row['detail_url']); $i++; } mysql_free_result($result); return $resultSet; }
$i = 0; foreach ($descriptions2 as $description2) { $resultSet->addDescriptionMoreByIndex($i, $description2->textContent); $i++; } $i = 0; $img_urls = array(); foreach ($detail_urls as $link) { $url = $link->getAttribute('href'); $featured[$i] = 0; if (strpos($url, '?featured=1') !== FALSE) { $featured[$i] = 1; $url = str_replace('?featured=1', '', $url); } $img_urls[$i] = 'http://streeteasy.com' . $url; $resultSet->addPropertyDetailLinkByIndex($i, $url); $i++; } foreach ($featured as $key => $f) { $resultSet->addPropertyFeaturedByIndex($key, $f); } foreach ($img_urls as $key => $imglink) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $imglink); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $page_img = curl_exec($ch); curl_close($ch); $img = preg_match('/(?U)id="large_photo"(.*)src="(.+)"/is', $page_img, $m) ? $m[2] : 'http://streeteasy.com/images/misc/no_photo_160.jpg'; $resultSet->addPropertyImageLinkByIndex($key, $img); }