Browse Source

read all car data limit 1000 per times

lionared 7 years ago
parent
commit
0d33734275
4 changed files with 14 additions and 5 deletions
  1. 1 0
      data/car/car_all.csv
  2. 1 0
      data/car/data_all.csv
  3. 11 4
      helper/car_convert/importer.php
  4. 1 1
      test/TestCar.php

File diff suppressed because it is too large
+ 1 - 0
data/car/car_all.csv


File diff suppressed because it is too large
+ 1 - 0
data/car/data_all.csv


+ 11 - 4
helper/car_convert/importer.php

@@ -101,7 +101,7 @@ class importer
     /**
      *  read data from file and fill into this _header & _data
      */
-    public function read_data()
+    public function read_data($start=0)
     {
         $encoding = $this->encoding();
         if($encoding == false) return false;
@@ -110,14 +110,21 @@ class importer
 
         $file = @fopen($this->_file, 'r');
         $i = 0;
-        while( !@feof($file) )
+        $limit = 1000;
+        $index = 1;
+        if( $start>0 ) {
+            $index = $start * 1000 - 1;
+        }
+        while( !@feof($file) && $limit > 0 )
         {
             if( $line = @fgets($file) )
             {
                 if($i == 0) {
                     $this->_header = explode(self::_delimiter, trim(iconv($encoding, 'UTF-8', $line)));
-                } else {
-                    $data[] = explode(self::_delimiter, trim(iconv($encoding, 'UTF-8', $line)));
+                } else if($i == $index) {
+                    $data[$index] = explode(self::_delimiter, trim(iconv($encoding, 'UTF-8', $line)));
+                    $index++;
+                    $limit--;
                 }
                 $i++;
             }

+ 1 - 1
test/TestCar.php

@@ -103,7 +103,7 @@ class TestCar extends PHPUnit_Framework_TestCase
 
     public function testAllCarInfo()
     {
-        $importData = new importer('../data/car/data_all.csv');
+        $importData = new importer('../data/car/car_all.csv');
         $importData->init_alias('all');
         $car_info = $importData->car_info(209);
         var_dump($car_info);