aeroswat Posted February 10, 2010 Share Posted February 10, 2010 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 ORDER BY school, last_name Quote Link to comment Share on other sites More sharing options...
aeroswat Posted February 10, 2010 Author Share Posted February 10, 2010 ORDER BY school, last_name I'd love to do that but I don't have a last_name field. I have a full name field >< Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 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). Quote Link to comment Share on other sites More sharing options...
aeroswat Posted February 10, 2010 Author Share Posted February 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2010 Share Posted February 10, 2010 The earlier you correct design problems, the less it costs in man-hours and money. Quote Link to comment Share on other sites More sharing options...
aeroswat Posted February 10, 2010 Author Share Posted February 10, 2010 The earlier you correct design problems, the less it costs in man-hours and money. True. Everything else works well with the current system though it's just that it somewhat limits a little bit of the possibilities for functionality. Thanks for your input. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted February 10, 2010 Share Posted February 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
aeroswat Posted February 10, 2010 Author Share Posted February 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
Wolphie Posted February 10, 2010 Share Posted February 10, 2010 Yes $sql = mysql_query("SELECT * FROM table1 WHERE field1 LIKE '%". $string ."%' OR field2 LIKE '%". $string ."%'"); Quote Link to comment Share on other sites More sharing options...
aeroswat Posted February 10, 2010 Author Share Posted February 10, 2010 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. 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.