Jump to content

Sorting Algorithm


aeroswat

Recommended Posts

My question is would a merge sort be my best bet for the following issue I have. I have a list of students that each belong to a school system. I need the list first and foremost sorted by school system and then by last name. So I figure what I could do at first is do a ORDER BY school system on my MySQL query then a sort on the last name with the merge sort. Would something else be more efficient all of the time?

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/
Share on other sites

A) Why not separate the name into separate columns, and

B) You can always use mysql string functions in the query to extract the last name, but this or any use of php code to accomplish this will always be slower than using option A).

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/#findComment-1010101
Share on other sites

A) Why not separate the name into separate columns, and

B) You can always use mysql string functions in the query to extract the last name, but this or any use of php code to accomplish this will always be slower than using option A).

 

Alright I guess i'll just take the dive and re-write the current system. So many pages of code I'm going to have to go through to change how everything is handled :(

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/#findComment-1010102
Share on other sites

A) Why not separate the name into separate columns, and

B) You can always use mysql string functions in the query to extract the last name, but this or any use of php code to accomplish this will always be slower than using option A).

 

You've just got to remember, the over-all system will thereby be improved by doing so.

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/#findComment-1010111
Share on other sites

One more question. Is there a way to check a combination of two fields for a string? Something like this

 

SELECT * FROM tbl WHERE FName+LName LIKE '%" . $fullname . "%';

 

While redesigning the system I'm trying to cut out all possibilities for error so I want the user to be able to search by ANY way to write the name. Only first name, only last name or both names

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/#findComment-1010120
Share on other sites

Yes

 

$sql = mysql_query("SELECT * FROM table1 WHERE field1 LIKE '%". $string ."%' OR field2 LIKE '%". $string ."%'");

 

Thank you but that isn't what I asked for. Let me give an example to better explain what I am trying to accomplish. If a user registers with the following name John Smith and they go to search for their registration information I want them to look-up by John or Smith or John Smith... Now If I am checking just 1 name it would be fine but if they enter the full name and I have split name columns this is not possible to do in that way. Also if they enter something like John Mac Smith it further complicates it because you can't make a for-sure string alteration to break it down before inserting in the query.

Link to comment
https://forums.phpfreaks.com/topic/191625-sorting-algorithm/#findComment-1010131
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.