Jump to content

[SOLVED] How to insert arrays from screen scrape into db?


Greaser9780

Recommended Posts

Sorry. Here is an example from NFL.com. I scraped a certain years stats then it printed this as the array:

  Array
(
    [0] => Array
        (
            [0] => Game Log
        )

    [1] => Array
        (
            [0] => 
        )

    [2] => Array
        (
            [0] => September
            [1] => Rushing
            [2] => Receiving
            [3] => Fumbles
        )

    [3] => Array
        (
            [0] => GAMEDATE
            [1] => Opp
            [2] => RESULT
            [3] => GS
            [4] => Att
            [5] => Yds
            [6] => Avg
            [7] => Lg
            [8] => TD
            [9] => Rec
            [10] => Yds
            [11] => Avg
            [12] => Lg
            [13] => TD
            [14] => Fum
            [15] => Rec
            [16] => Yds
            [17] => TD
        )

    [4] => Array
        (
            [0] => 09/11
            [1] => @OAK
            [2] => W 27-0
            [3] => Yes
            [4] => 31
            [5] => 131
            [6] => 4.2
            [7] => 58
            [8] => 1
            [9] => 3
            [10] => 18
            [11] => 6.0
            [12] => 10
            [13] => 0
            [14] => 0
            [15] => 0
            [16] => 0
            [17] => 0
        )

Link to comment
Share on other sites

It really all depends on how the database is done. If you are going to be parsing a string for the GAMEDATA than you you can use 1 table to enter all the data in and just set : or something similar as the separator string. If you want to store each value into its own field, well that calls for multiple tables. Here is the example for what I stated above:

 

<?php
$log = $nflArr[0][0];
//$data = $nflArr[1];
foreach ($nflArr[1] as $data) {
$entry .= $data . ":";
}
$entry = substr($entry, 0, -1);

foreach ($nflArr[3] as $gData) {
$gameData .= $gData . ":";
}

$gameData = substr($gameData, 0, -1);

foreach ($nflArr[4] as $date) {
$dayData .= $date . ":";
}
$dayData = substr($dayData, 0, -1);

mysql_query("INSERT INTO tblName `entry`, `gamedata`, `daydata` VALUES('".$entry."', '".$gameData."', '".$dayData."'");
?>

Link to comment
Share on other sites

Actually what I am looking to do is gather the info(already done). Then I want to take each stat and create a number out of it. Example: A touchdown is worth 6 points. $tdpoints = ($touchdowns * 6).

So I guess I'm wondering do I need to insert it into a db first and then in another script pull it out and do the math on it, OR can I just do the math somehow before inserting it into the db. Also I am not looking to utilize all the arrays gathered. I just want to use the stats from the day that I am choosing. But with mmy class it extracts all the data after a certain phrase in the page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.