diff --git a/README.md b/README.md
index 001aed9..f03573e 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,29 @@ echo "
";
echo "Average price: ".(intval($total_price / $result_count)); # Prints 39239.94
```
+## Other Examples
+
+Get the list of makes from [Dubizzle] ([Live Demo](http://www.osoobe.com/devlabs/php/demo/dubizzle-php/demo/get_makes.php)):
+```php
+
+use Dubizzle\Category;
+
+$category = new Category();
+$makes = $category->get_makes(Category::$uae["categories"]["options"]['cars']);
+```
+
+
+Get the list of models from [Dubizzle] ([Live Demo](http://www.osoobe.com/devlabs/php/demo/dubizzle-php/demo/get_models.php)):
+```php
+
+use Dubizzle\Category;
+
+$category = new Category();
+$mmodels = $category->get_models(Category::$uae["makes"]["options"]['audi']);
+```
+
+
+
## Search Parameters
### General
diff --git a/demo/demo2.php b/demo/demo2.php
index 8014233..c6d5060 100644
--- a/demo/demo2.php
+++ b/demo/demo2.php
@@ -14,7 +14,7 @@
"min_year"=>2007,
"num_results"=>'all'];
-$uae = new Search($params, 50);
+$uae = new Search($params, 120);
$query = $uae->search();
$query->fetch();
@@ -26,6 +26,9 @@
$total_price += $result["price"];
}
+echo "URL: ".$uae->query_url();
+echo "
";
+echo "
";
echo "Num. Results: ".$result_count;
echo "
";
echo "
";
diff --git a/src/Dubizzle/Results.php b/src/Dubizzle/Results.php
index 5d70789..1383944 100644
--- a/src/Dubizzle/Results.php
+++ b/src/Dubizzle/Results.php
@@ -45,8 +45,8 @@ public static function get_more_results($html){
$clean_html = $purifier->purify($html);
# Build a HTML parser to search for items.
- $this->dom = new Dom;
- $this->dom->load($clean_html);
+ $dom = new Dom;
+ $dom->load($clean_html);
# Get result items from the HTML.
$items = $dom->find(".listing-item");
@@ -125,7 +125,7 @@ private static function parse_items($items){
* This function also parse the initial result page and fetch additional
* pages to build the list of associated arrary for item information.
*/
- public function fetch(){
+ public function fetch($start_page = 2){
# Track time;
$this->time = time();
@@ -145,16 +145,17 @@ public function fetch(){
$num_results_on_page = count($items);
+
# Get the total number of pages.
- try{
- $last_page_query = $this->dom->find('.paging_forward #last_page')->getAttribute("href");
- preg_match("/page=(\d+)/", $last_page_query, $num_pages_query);
- if(isset($num_pages_query[0][1])){
- $this->num_pages = intval(explode("=", $num_pages_query[0])[1]);
- }else{
- $this->num_pages = 1;
- }
- }catch(Exception $e){
+ $last_page_query = $this->dom->find('.paging_forward #last_page')->getAttribute("href");
+ if(empty($last_page_query)){
+ $last_page_query = $this->dom->find('.paging_forward a')[1]->getAttribute("href");
+ }
+
+ preg_match("/page=(\d+)/", $last_page_query, $num_pages_query);
+ if(isset($num_pages_query[0][1])){
+ $this->num_pages = intval(explode("=", $num_pages_query[0])[1]);
+ }else{
$this->num_pages = 1;
}
@@ -163,7 +164,6 @@ public function fetch(){
if($this->num_results > $this->total_results || $this->num_results == "all"){
$this->num_results = $this->total_results;
}
-
if($num_results_on_page > 0){
$page_needed = intval($this->num_results / $num_results_on_page );
}else{
@@ -172,8 +172,8 @@ public function fetch(){
$page_urls = [];
$base_url = preg_replace("/page=(\d+)/", "", $last_page_query);
- for($i = 2; $i <= $page_needed; $i++){
- array_push($page_urls, $this->url.$base_url."&page=$i");
+ for($i = $start_page; $i <= $page_needed && $i <= $this->num_pages; $i++){
+ array_push($page_urls, $this->url."&page=$i");
}
# Fetch additional pages.