Jump to content

PHP and SQL Help


tapupartforpres

Recommended Posts

Hello.  I was wondering if someone could point me in the right direction. 

 

I have an .csv file with about 3.1 million names.  In the .csv file I have 2 columns:  zip code and a form id number.  Depending on the ID number of the document, it would preview so they know they have the right form.

 

What I need it to do is to pull the number of records from the zip code and display them.  So for zip code 23313 it should show that there are say 2,000 records.  Then they would select the form they need those records printed on.  It would then return a preview of that form.  If they approve the count and the form, I would need to see if I can either 1) have that list emailed or 2) have the list stored somewhere for download.  I would also need the form number emailed so we know which form to print it on.

 

Obviously I need to get the .csv file into the SQL database.  But what steps should be taken next?

 

Any ideas?  Thanks

Link to comment
Share on other sites

You are asking a lot of questions in there. I would suggest you take one part at a time and ask specific questions as needed. Getting 3 million records from a flat file into the database is the first problem to overcome. Normally I would use file() to read the file into an array. And then process it for a INPUT statement.

 

If the zip ode and form id were separated on each line by a comma I would do something like this:

 

$file="the_file.csv";

$data = file($file);

//Process data
foreach ($data as $record)
{
    $record_data = explode(',', $record);
    $insert_records[] = "('".trim($record_data[0])."', '".trim($record_data[1])."')";
}

//Create query string
$query = "INSERT INTO table (ssn, form_id)
          VALUES " . implode(',' , $insert_records);
//Run query
mysql_query($query) or die (mysql_error());

 

However, with 3 million records you will most likely run into problems. You may need to find a workaroound to process the file in pieces. But give that a try to see if it will even process that many records. Would be a good idea to track system resources during the process to understand the load on your server.

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.