-6

I am parsing table data via this code

$table = $myurl->find('table', 3);
$rowData = array();
foreach($table->find('tr') as $row)
            {
                 $flight = array();
                 foreach($row->find('td') as $cell) 
                        {
                        $flight[] = $cell->plaintext;
                            }
                $rowData[] = $flight;
            }   


        $rowcount= count($rowData);
        $a       = ($rowData[2][2]);
        $b       = ($rowData[2][1]);

It works well when table exists. but when no table exist it shows error.

This error
Call to a member function find() on null in C:\ .............abc.php on line 3
on following code.

    foreach($table->find('tr' as $row))  

I want to hide error. In case of no table or no row it should give "N/A" to the variables declared in the end of the code.

  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – MonkeyZeus Aug 23 '16 at 12:48
  • please take two minutes and get the answer before asking because it is very basic, minimal will! – Maxi Schvindt Aug 23 '16 at 12:57

2 Answers2

1
include('simple_html_dom.php');
$html = file_get_html('table.html');
$ret = $html->find('.ctable',0);
$name =$ret->children(1)->children(0)->plaintext ;  
$email =$ret->children(1)->children(1)->plaintext ;
$address =$ret->children(19)->children(2)->plaintext ;

this might work

Owais
  • 11
  • 1
  • 2
0

i have used this

include('simple_html_dom.php');
    $html = file_get_html('table.html');
    $ret = $html->find('.ctable',0);
    $name =$ret->children(1)->children(0)->plaintext ;  
    $email =$ret->children(1)->children(1)->plaintext ;
    $address =$ret->children(19)->children(2)->plaintext ;