Jump to content

Comparing Database data and new data help


SiriusB

Recommended Posts

I am trying to create a PHP script that reads in a file, parses it for the data I want and compares it to the data I have in a database.

 

The data is points and ranking information for a Folding@Home Team.  Every week someone creates a news item with points gained by each team member for that week and other info.  This is done manually and takes a lot of time.  I hope for my script to automate as much of it as possible.

 

The script was to run as follows:

 

Download and parse latest statistics into 2D array

Compare usernames in array to usernames held in Database

Any new usernames and their respective points/rank to be added to database

 

Compare points in 2D array of each user to those held in database.

Output username and points gained

 

I thought I had a working script until I actually tested it on real data, and realised I missed something rather obvious - the order of usernames from the parsed file is not going to be the same order as in my database - due to people moving up and down the ranks.  So i can't just get a recordset from the db and run a simple loop to compare it to the parsed data.

 

I am not sure how to go about comparing the database information with the parsed data that works around the fact the data could be in any order.  The only thing i can think of is:

 

 

foreach item in $parsed_data_array

    query database for $parsed_data_array=>username

        if(number of results == 0)

          build new insert query for current username

        else

          continue

 

I don't know if this works [haven't tested yet] but I can't help feel it is a little DB intensive.  There could be up to 200 queries being sent to the database.  This can be minimized by adding extra criteria, like ignoring inactive users of course.  Is this a viable solution or is there a much better way of doing this?

 

Sorry if anything is unclear.  Just ask and I will explain further if required.

           

 

Link to comment
Share on other sites

This forum is designed to be used for help with a specific coding question/error.  To me it looks as though you need something developed from the ground up.  I would either work on some of the code and post it on here to ask follow up questions or would look into the other sections of the forum where you can hire a developer.

Link to comment
Share on other sites

I am not asking for this thing to be done for me.  At no point did I ask for that nor did I imply it.  I haven't even asked for any specific code.

 

Read my post again.  I asked a specific question about how best to compare a recordset from a database with data parsed from a file.  I even gave pseudo-code as to the solution I thought of and have asked if this is a good way of doing it.  If not, what is the alternative?

 

I only mentioned the purpose of the script to give a background to my problem and why I need to do what I am asking for. 

 

I appreciate your input, but in this case you have made an incorrect assumption.

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.