473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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

php

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. require "phpQuery/phpQuery-onefile.php";
  4.  
  5.  
  6.             // Load page
  7.             $ch = curl_init();
  8.             curl_setopt($ch, CURLOPT_URL, 'http://mysite.net/');
  9.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  10.             $html = curl_exec($ch);
  11.             curl_close($ch);
  12.  
  13.             // Create phpQuery document with returned HTML
  14.             $doc = phpQuery::newDocument($html);
  15.  
  16.             $lotsOfArticles = $doc->find('table.articles');
  17.  
  18.                 foreach( $lotsOfArticles as $articles)
  19.                 {
  20.                 // Date is on the second tr - fifth td, first a, i want the html of the link    
  21.                 $LinkTableRow  = $articles->find('tr').next();
  22.                 $LinkTableData = $LinkTableRow->find('td').eq(4);
  23.                 $Link   = $LinkTableData->next('a')->html();
  24.  
  25.                 print_r($Link);
  26.  
  27.  
  28.                 // would like a list of Links from every article
  29.                 // i would like to access them like this - $link[0];
  30.                 }
  31.  
  32. ?> 
  33.  
  34. </body>
  35.  
  36.  
  37.  
html

Expand|Select|Wrap|Line Numbers
  1.  
  2.       <table class="articles">
  3.          <tr>lots of other tags here</tr>
  4.          <tr>
  5.             <td>lots of other tags here</td>
  6.             <td>lots of other tags here</td>
  7.             <td>lots of other tags here</td>
  8.             <td>lots of other tags here</td>
  9.             <td><a> Link here </a></td>
  10.          </tr>
  11.  
  12.       </table>
  13.  
  14.       <table class="articles">
  15.          <tr>lots of other tags here</tr>
  16.          <tr>
  17.             <td>lots of other tags here</td>
  18.             <td>lots of other tags here</td>
  19.             <td>lots of other tags here</td>
  20.             <td>lots of other tags here</td>
  21.             <td><a> Link here </a></td>
  22.          </tr>
  23.  
  24.       </table>
  25.  
  26.       <table class="articles">
  27.          <tr>lots of other tags here</tr>
  28.          <tr>
  29.             <td>lots of other tags here</td>
  30.             <td>lots of other tags here</td>
  31.             <td>lots of other tags here</td>
  32.             <td>lots of other tags here</td>
  33.             <td><a> Link here </a></td>
  34.          </tr>
  35.  
  36.       </table>
  37.  
Aug 28 '13 #1
0 1280

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
3
by: AK | last post by:
Hi Everyone, For Last a few weeks I have been involved with performance tuning of an application. I have observed that if I do a loop over a collection (ArrayList/HashTable) which has 50000...
16
by: Islam Elkhayat | last post by:
In my web application i use satalite assembly to localize my web form.. Instead of set the each control text to the resourcemanager getstring() method i try to use foreach loop private string...
1
khalidbaloch
by: khalidbaloch | last post by:
hi every one, how are you folf , hope fine dear Friends i want to get values of multi-dimensional arrays using foreach loop and after that print out the html using an other while loop , i tried...
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
1
by: vit159 | last post by:
I have Data Recive it from stordProceder and i want to Get this data using foreach loop to equal it with local variable
10
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I wanted to go through each entry(?) of ArrayList and remove some particular entry. So I tried following but it throws exception at runtime: foreach (myEntry entry in myArrayList) {...
1
by: djmeltdown | last post by:
I'm having trouble getting a foreach() loop to insert a record into a MySQL Database. Which I've never had any trouble before, it just seems quirky. I've tried the mysql_query statement without a...
1
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.