How can i use phpQuery to find child of a child using a foreach loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke
    New Member
    • May 2012
    • 14

    How can i use phpQuery to find child of a child using a foreach loop

    Im new to phpQuery This is my best effort below. Which doesn't work at all.

    php

    [code=php]

    <?php
    require "phpQuery/phpQuery-onefile.php";


    // Load page
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_URL, 'http://mysite.net/');
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, true);
    $html = curl_exec($ch);
    curl_close($ch) ;

    // Create phpQuery document with returned HTML
    $doc = phpQuery::newDo cument($html);

    $lotsOfArticles = $doc->find('table.ar ticles');

    foreach( $lotsOfArticles as $articles)
    {
    // Date is on the second tr - fifth td, first a, i want the html of the link
    $LinkTableRow = $articles->find('tr').nex t();
    $LinkTableData = $LinkTableRow->find('td').eq( 4);
    $Link = $LinkTableData->next('a')->html();

    print_r($Link);


    // would like a list of Links from every article
    // i would like to access them like this - $link[0];
    }

    ?>

    </body>


    [/code]

    html

    [code=html]

    <table class="articles ">
    <tr>lots of other tags here</tr>
    <tr>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td><a> Link here </a></td>
    </tr>

    </table>

    <table class="articles ">
    <tr>lots of other tags here</tr>
    <tr>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td><a> Link here </a></td>
    </tr>

    </table>

    <table class="articles ">
    <tr>lots of other tags here</tr>
    <tr>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td>lots of other tags here</td>
    <td><a> Link here </a></td>
    </tr>

    </table>
    [/code]
Working...