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