Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts

    assign variable to html cell value in table

    using both separate tables in this file

    www.maidenerleghweather.com/GFS/18z-17-01.html

    how easy is it to write a code to assign a variable to a cell value?

    eg I want to grab the 3rd row and the 3rd column.

    is php any use?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Unless you plan to retrieve those static table values using parameters in the URL from a hyperlink or put the values in a form it would be kind of pointless as your script is already completed execution when the page gets to the browser.

    Maybe it would be better if you explained what it is you are trying to do.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    thanks.

    I want to do various things such as count how many times the max temp falls under 6c or the few point under zero.

    I want to then add these totals together.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Where are you getting the data from that goes into the table? Is it coming from a database? If so you should do your calculations when you retrieve that data before you populate the table.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    its from a third party so I have no control.

    the only thing that i do have is the html script, which is accessed via the url posted above.


    any ideas?
    Last edited by muppet77; 01-19-2012 at 05:44 PM.

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by muppet77 View Post
    its from a third party so I have no control.

    the only thing that i do have is the html script, which is accessed via the url posted above.


    any ideas?
    Oh ok I guess I misunderstood then. So that site you linked to is not yours and you want to grab the data from their static table to use for some calculations?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    yes, that's right.

    is this possible?

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ok in that case you will need to parse their html file then. Hopefully they are consistent with how they format it otherwise this will be a pointless effort.

    Here is another thread where someone was looking to do something similar where they were given thousands of html files that they had to parse to grab specific data out of tables and save it to a CSV file. You will want to take a very similar approach. If you can use the DOM to parse it that would be the simplest otherwise you will have to get creative with using regular expressions to grab the data.

    PHP Parsing Challenge - A real sample project- Please help
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    thanks, I have no idea what that is nor where to start. sorry!

  • #10
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well to get started obviously the first thing you would need to be able to do is use PHP to grab the html from that other site. You can do this a few ways. One way is to use the file_get_contents() function. Something like:

    $html = file_get_contents('http://www.maidenerleghweather.com/GFS/18z-17-01.html');

    You could also use cURL to grab it http://php.net/manual/en/book.curl.php

    Once you have their page in a string you need to parse it using one of the 2 methods shown in the other thread I posted a link to. I'd probably start with trying DOM if their HTML is well formed enough to use DOM. If not regular expressions will always work but are definitely not easy to define.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Didn't I answer this one before ... on how to parse your static HTML table?

    I swear this was the same topic:
    use php to turn html table data to php variables? RESOLVED

    I had a heck of a time parsing it too ... what an HTML mess.
    If I remember correctly, I even suggested that you contact them and
    ask them if they can provide an API or at least an XML file of data.
    It would so easy for them to do that ... one small script.

    Even if they could give you a link to a CSV file ... even that would be OK.
    What you're doing seems so obsolete and messed-up. It's 2012 for cripe sakes!



    .
    Last edited by mlseim; 01-19-2012 at 11:17 PM.

  • #12
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    mLseim, yes if you recall it was only possible to extract the values with hyperlinks attached to them.

    I'd really like to pick and choose the data columns.

    those parse tutorials look tricky. I don't really get which tags I am looking for.

    for example which tags do I strip out for then temperature?

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Which temperature columns(s) are you trying to get?
    Let me know what the column heading is on the ones you want.

  • #14
    New Coder
    Join Date
    Dec 2011
    Location
    Reading, Berkshire, UK
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    max temp
    min temp
    td
    total precip
    500-1000thickness
    850mb temp
    500mb temp

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    the rows ...

    td
    850mb
    500mb

    all have the same <HTML> in them.
    I'm stuck on that now ... maybe I'll think of something later on.


    EDIT: question ...
    Will there always be the two table sections?


    .
    Last edited by mlseim; 01-20-2012 at 05:16 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •