SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot croman's Avatar
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing Data into a Database from a Text File

    I have attempted to tackle this a few times but I never really get anywhere. However, I am ready to give it another shot since I really really really want to learn how to do this

    I run a Madden PC league. (actually a couple of them) and right now when I get the game results from a game, I have to use a 3rd party utility that turns it into a csv file so that I can import it into the database. It works, but it is very time consuming since I have to do it 16 times per week and then import 16 different files into the database.

    So what I would like to do is figure out how to automate all of this. My first step is to learn how to take a text file and parse out certain data from it.

    So lets start with this.. I will give an example of a Gamelog and I would like to see if someone can help me turn it into a few variables. If I can learn how to do that, I will start tackling the rest of it.

    Also, if anyone has any ideas of a tutorial or something similar that I can read to learn this stuff, please let me know. (sorry, I am one of those that have a hard time understanding the php manual)

    Ok, here is a sample of a gamelog

    Code:
    Team               Q1   Q2   Q3   Q4   OT      FINAL
    Bears              10    0    0    7    0         17
    Titans              0    3    7    0    0         10
    
    Game Statistics:                    Bears     Titans
    First Downs                            10         17
    Third Down Conversions                  4          4
    Third Downs                            12         12
    Out of this, I would like to get something like
    $team1 = Bears
    $team2 = Titans
    $team1q1 = 10
    $team1q2 = 0
    $team1q3 = 0
    $team1q4 = 7
    $team1q5 = 0
    $team1score = 17
    $team2q1 = 0
    $team2q2 = 3
    $team2q3 = 7
    $team2q4 = 0
    $team2q5 = 0
    $team2score = 10

    $team11stdown = 10
    $team13rdconv = 4
    $team13rddown = 12
    $team21stdown = 17
    $team23rdconv = 4
    $team23rddown = 12


    Well, you get the idea. I just have no idea on how to go about doing something like this.

    Thanks in advance for any advice and/or code snippits that can help me

  2. #2
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a good thing to cut you're teeth on.

    I'd recommend anyone learn file functions before messing around with lazy databases.

    First thing first, the format of your text file would certainly add to the complexity of what you're doing. Do you have any control over how the file is formatted?

    Also, what is all of the white space made up of? Is it spaces or tabs?

    First of all, get acquainted with Filesystem Functions, you might want to look at fgetcsv.

    Identify your problem. The problem comes in three parts: 1) get the data in from the file, 2) format the data, 3) export the data to a database...

  3. #3
    SitePoint Zealot croman's Avatar
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not have any way of changing the file, that is the way the game exports it upon completion of a game.

    How can I tell if it is spaces or tabs? I would guess spaces

    I will look at those links you gave me, my problem is all of that stuff always looks gibberish to me and I never understand it.

    Thanks

  4. #4
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by croman
    I do not have any way of changing the file, that is the way the game exports it upon completion of a game.

    How can I tell if it is spaces or tabs? I would guess spaces

    I will look at those links you gave me, my problem is all of that stuff always looks gibberish to me and I never understand it.

    Thanks
    I think you'll find most people here will help, but they -- like me -- will stop short of actually doing it for you.

    I'm quite happy to help you through if you're willing to learn what's needed...

  5. #5
    SitePoint Zealot croman's Avatar
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am definately willing to learn. That is why I posted only a snippet of the Gamelog. The actual gamelog is about 20x that and has alot more "formats" in it as far as the way the data is displayed.

    Unfortunately, with PHP.. I have a heard time learning from reading the PHP manual. I have done all of my learning so far by looking at code snippits, reading tutorials, etc.. (Unfortunately, I have not found any kind of tutorial or anything like that based on what I am trying to do here).

    Thanks

  6. #6
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tutorials will take you so far, but you're in luck!

    Believe me, bar far the best way to learn PHP is to do so with a project in mind, which you have.

    I'm sure other members could recommend a good book, but my recommendation is Beginning PHP4.

    Maybe you should scout round the forum looking for threads on book suggestions, or if there is no such thread [which I doubt] start your own and ask people...


Bookmarks

Posting Permissions

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