devofash Posted September 15, 2009 Share Posted September 15, 2009 Hi Guys, Need a bit of help. Basically I want to merge duplicate records into one in an excel csv file. example: col1 - col2 - col3 - col4 user 1 - A user 2 - B user 3 - C user 1 - B user 1 - C into col1 - col2 - col3 - col4 user 1 - A B C user 2 - B user 3 - C I have a form where user submits the information and it is then stored in the csv file. I have managed to store the data into the csv but can't seem to sort the data as required. Was wondering if anyone can help me out with a bit of code. I dont know where to start with merging so I don't have any code to post. Any help is much appreciated. Thanks dev Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted September 15, 2009 Share Posted September 15, 2009 The data is being passed through to the script from an html form. What does that form look like? How are you holding the data in your script before writing it to CSV? In an array? Quote Link to comment Share on other sites More sharing options...
devofash Posted September 15, 2009 Author Share Posted September 15, 2009 Thanks for coming back to me. forgot to mention I need to keep the orignal csv, what I need is a script that will read all the records from the orignal file and sort it out according to the requirement and save a new copy. Its just a html form with 2 input fields called account number and order number. This is the code I use to write to the CSV file. $cvsData = $accountnumber . $ordernumber . "\n"; $fp = fopen("datafile/registrations.csv", "a"); if($fp) { fwrite($fp, $cvsData); fclose($fp); } else { } Quote Link to comment Share on other sites More sharing options...
devofash Posted September 16, 2009 Author Share Posted September 16, 2009 any ideas guys ?? could really do with some help. Quote Link to comment Share on other sites More sharing options...
devofash Posted September 21, 2009 Author Share Posted September 21, 2009 ... Quote Link to comment Share on other sites More sharing options...
syed Posted September 21, 2009 Share Posted September 21, 2009 Your csvData variable is assigned the value of account number and order number, but it appears that there is no usage of the comma to separate the values. It should be something like this $cvsData = $accountnumber . "," .$ordernumber . "\n"; What you should do is before saving to the csv file. Store the data into a 2D array as such. $DataColumn[] = $accountnumber; $DataColumn[] = $ordernumber; $DataRow[] = $DataColumn; Now that you have the data stored into a 2D array you can do some sorting using some of the array functions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.