Search code examples
phpdomsimple-html-domdomparser

PHP Script is skipping only first row


I have simple html dom parser with script which saves parsed data into database. But here the dom skips first row while continuously parses all other data. The url from which I'm parsing the data is : http://krushimitra.co.in/4.html.

also my php script is like...

............
ini_set('max_execution_time', 0);

error_reporting(E_ALL);
ini_set('display_errors', '1');
$url='http://krushimitra.co.in/4.html';
include('dom.php');
$html=file_get_html($url);


    $record_find='first';
    foreach($html->find('table#GridView1') as $e){

                if($record_find=='first'){ $record_find="second";continue;}
         $i=1;
                 foreach($e->find('tr') as $e1){
                     if($i<4){$i++;continue;}
                                 $some=trim($e1->find('td', 0)->innertext);
                                 $somea=trim($e1->find('td', 1)->innertext);
                                 $someb=trim($e1->find('td', 6)->innertext);

                                 $col=trim($e1->find('td', 0)->colspan);
                                 if($col == 10){......
...........

and my dom is @ http://sourceforge.net/projects/simplehtmldom/files/. I had chnaged the define('MAX_FILE_SIZE', 60000000);.

I don't know why my script is not consider first row, here it is "Bhatiya (NIL Transaction)" which have colspan of 10. Please help me resolve this issue.


Solution

  • Finally after trying so many methods, I reach at best solution, which is a lot easy step. Only need a two small changes at same instance... snippet:

    ....
    
                    if($record_find=='first')
    //{ $record_find="second";continue;} // Removed this line
             $i=1;
                     foreach($e->find('tr') as $e1){
                         if($i<3){$i++;continue;} //made changes here as suggested by @legiero.
                                     $some=trim($e1->find('td', 0)->innertext);
    ........