Jump to content

Complex Array Sort & Search


NovaRising

Recommended Posts

I'll try to make this as simple as possible but please understand that I'm an amateur PHP programmer who needs to use the documentation every time he codes...

 

So I'm building this tool that can search .csv files to find duplicate rows or records or ones that are very similar (last name match, city match, address match etc...). These rows usually contain something like this:

User ID |First Name |Last Name |Address Line 1 |City |State |

655874TomJerry541 Disney LandHollywoodCA

 

This is very easy to fix by sorting and matching like below

 

if($crecord[3] == $nrecord[3] && $crecord[1] == $nrecord[1] && $nrecord[0] != ""){

where $crecord = the current row and $nrecord = the next row.

 

However, what I'd like to do is have the user able to upload a spread sheet and have the script automatically detect their column titles. Then they can choose search options like...match first name to last name etc...

 

The idea is that you can easily find duplicate records or compare two data sets to find the ones that match or don't match.

 

I already created a way for a user to upload a .csv and generate a form based on the fields titles found in the CSV.

example.jpg

 

My questions are,

 

1. How do I build a PHP loop that can take all the user input options and create a search string that will return accurate results?

 

I don't need the exact script. I just need a general idea of how to go about it. Would switch/case statements with every possible option be the best rout?

 

2. Will this method work if there are some 33,000 rows?

I'm concerned that I will create a mess that is highly ineffecient and kills the server.

 

I thought about taking the first criteria and doing an array search, if a result was returned then the script would go to the second match...and if all fields matched it would take this row and put it in another array which would then be output at the end. This method would seem like it would work...

 

 

Please ask for questions if you need clarification...

 

 

Link to comment
https://forums.phpfreaks.com/topic/173956-complex-array-sort-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.