Xpath Table Within Table - php

I am having a bit of a problem of scraping a table-heavy page with DOMXpath.
The layout is really ugly, meaning I am trying to get content out of a table within a table within a table.
Using Firebug FirePath I am getting for the table element the following path:
html/body/table/tbody/tr[3]/td/table[1]/tbody/tr[2]/td[1]/table[1]/tbody/tr[3]/td[4]
Now, after endless experimenting I found out, that with a stand alone table, I need to remove the "tbody" tag to make it work. But this doesn't seem to be enough for tables within tables.
So my question is how do I best get content out of tables within tables within tables?
I uploaded the file which I am trying to scrape here:1

i have gone through with the same problem as yours scrapping a source of complicated and not well formatted html where i want to get the values in a table inside another tables..
i came with the approach of eyeing the part that i want to get with some series of function like this:
function parse_html() {//gets a specific part of the table i chose to extract the contents
$query = $xpath->query('//tr[#data-eventid]/#data-eventid'); //gets the table i want
$this->parse_table();
}
function parse_table() {//
$query = $xpath->query('//tr[#data-eventid="405412"]/td[#class="impact"]/span[#title]/#title');...etc//extracts the content of the table
$this->parseEvaluate();
}
function parseEvaluate(){
...verifying values if correct
}
just giving the idea..

How about:
//*[contains(text(),"GRABME")]
I know that's probably not what you want, but you get the idea. Identify a pattern and use that pattern to construct the xpath.

Related

PHPWord Prevent rows from the same table appearing on different pages

thanks for help with previous PHPWord issue. I have another.
I'm creating documents with tables where each table is basically used as a stylized container for a list of items. For example, in my case i have a collection of legal definitions. Each definition has a code, title, and textual description that appears in a table. So when there's multiple definitions, each definition has its own table, and appears like so:
and so on. Each table isnt really a table, its more i'm kind of hijacking tables to stylize my document. The problem is when I have a long list of items, invariably some of the tables will be split between pages where the top row of the table will be at the very bottom of the page and bottom row of the table will be at the very top of the next page, like so
This is very undesired. Is there any way to tell PHP word that "hey, if this table is going to be split between pages, just put the whole table on the next page" ??
I'm also using PDFmake for making pdf's and it has a pageBreakBefore function that can be used for exactly this purpose. I notice that paragraphs have a pageBreakBefore style which can force each pragraph to appear on a new page, but this isnt what i'm looking for. Is there some way i can maybe get into how PHPWord builds the document to put a conditional test in maybe?
Any input is greatly appreciated thanks.
I had the same problem .... and found the answer today in "normal" MsWord documentation. I found the equivalent in the phpWord doucmentation, tried it and it works:
In your paragraph formats, set 'keepNext' => true

How do I implement an Angular-like filter function in php?

I have a page that is full of tables (generated by a foreach loop) and every row displays, among other things, a month.
Now I want to give the user the ability to choose a month and have only the table rows for that current month displayed (or no table at all if that month is missing from the table). A bit like the filtering function in Angular JS.
I'm still a bit new to php and the only solution I can up with is to handle the whole thing somewhat clumsily with modifying CSS classes and having the superfluous rows hidden by CSS.
What would be a more efficient way to do this?
Your problem is related with the filter alternate of angular into php.
As you know php is server side. So, if you want to get the filter after a reload or by ajax method, you need a $_GET variable.
Use a different query string in your url for each click of each button. Then retrieve the GET variable and use it to get data from database for relevant category.

Programming a Tags Feature in PHP

How would I go about writing up a basic tags feature? (similar to the one on this site)
I'm struggling coming up with good logic with little redundancy and would like a more experienced programmer's take on this.
The site I have is fully developed as of right now and has a search feature (searches through titles) - I'm just looking to expand on this and allow the search to sift through tags as well.
Edit:
I was considering adding a row on to my main table called "tags". Then separating them by spaces.
But I have also thought about create a new table and using the same id's from my main table, creating tags in this manner.
I'd suggest 2 tables. One contains Tags - the name of the tag, a tag id, any anything else you want to keep track of on a tag. Also create a relationship table that connects your article/post id to the tag id. You won't repeat data in the database, you should be able to search the tags and join tables together to come up to return articles, and also query the tags if you want to display them along with posts.

Tagging system similar to the one used in this site

i need to implement a tagging system looking exactly like the one we are using now. I'm new to the web developing so i'm having a few problems and i would like to start from an example but i can't find one.
In particular i would need the frontend part that, i suppose, parse an xml received from the server and print it like those cool squares with the tag in it. I don't need something exactly like this, an example of something similar would suffice.
why do you use or supposed this data to be sent as xml ? do u save it in xml in the begining ? i suppose you should save your data in database . and create a table for every unique tag and then create a bridge bettween the posts table and the tag table containing every post with every tag linked to it .
Have you looked at the Tag plugin by CakeDC? Might save you some time.

Dynamically generate a table with specific rowspans in PHP?

I've been racking my brain about an easy way to generate an HTML table with rowspans with PHP that would look like this, numbers indicating each cell's rowspan:
I noticed that there is sort of a pattern in the rowspans if you go from left to right, top to bottom: 1,3,7,1,1,1,1,1,3,1,1. I'm not sure if that matters.
Also, I wonder if it's possible to use any method for the table above for a table like this:
maybe addressing your second example first is easier, but it might be adapted to the first example.
the structure of the tables in html is obtained using the rowspan an colspan properties.
try to picture the table as a closet, the rows as drawers and cells as boxes inside those drawers.
with these properties, u can "merge" the cells throughout rows and/or columns.
my approach would be to set a minimal block with the appearance and data that you need, ie your second example, and write it down in html.
the "php-cycle-the-thing-up" part would require you to use that html "template" in the loop dropping your recordset data in the td portions of the html.
in that way, i think you might get what your looking for.
on the other side, if you need the php to create the table dynamically, and merge the cells automatically in a set pattern, or even ignoring the pattern and simply adapt the structure as the data is coming, it would probably be better to look at the structure from the end.
because of the way that tables are built with html, nesting table-tr-td, building cycles with this look is tricky. have you considered simply nesting divs?
i'm new to stackoverflow, i wanted to comment but by the time i finished this, i couldn't remove the answer nor comment the question, sorry if this didnt quite help you... :S
write down, come up with the recursion formula for the table. you need to come up with the math with the least number ideally ZERO conditional statements.
it's not that hard. for a desktop, i use three columns if it detects a mobile devices, my php automatically switches to 1 or 2 columns depending upon screen size

Categories