rhock_95 Posted September 29, 2007 Share Posted September 29, 2007 A script lets users search a database for 'last name' and displays those results what is the simplest way to let them sort those (further query) results by 'first name' ? Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/ Share on other sites More sharing options...
aebstract Posted September 29, 2007 Share Posted September 29, 2007 When you search for results by first name, limit to only the ones that you grabbed when searched by last name. Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358070 Share on other sites More sharing options...
rhock_95 Posted September 29, 2007 Author Share Posted September 29, 2007 what I am hoping to do is just reuse the original query and run a second query using the original $query (variable) what I am seeking is the correct syntax $sql="select * from my_table where last='$query' and first LIKE '%$first%' ORDER BY first"; the above is not working "$query is the original "last name" searched for Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358076 Share on other sites More sharing options...
sasa Posted September 30, 2007 Share Posted September 30, 2007 try $sql="select * from my_table where last='$query' ORDER BY first"; Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358322 Share on other sites More sharing options...
rhock_95 Posted September 30, 2007 Author Share Posted September 30, 2007 thanks for the reply...but that does not allow the user to select a "first initial/name" etc... Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358372 Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 $sql="SELECT * FROM my_table where last='$query' AND first LIKE '%$first%' ORDER BY first"; Try that, post back the results. Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358381 Share on other sites More sharing options...
sasa Posted September 30, 2007 Share Posted September 30, 2007 i don't understund your problem is user input full last name or just part of it is user input somethin from first name can you post some example what user input, and what script must return Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358542 Share on other sites More sharing options...
rhock_95 Posted September 30, 2007 Author Share Posted September 30, 2007 i don't understund your problem is user input full last name or just part of it is user input somethin from first name can you post some example what user input, and what script must return The initial query posts (last) last and returns the records that match the "$query" what I'm trying to do is run a second query (from an integrated form $first) that when submitted sorts the initial results by a second column (first)...where the second query input can be just a single letter (first initial etc)... Quote Link to comment https://forums.phpfreaks.com/topic/71188-sort-results-by-another-column/#findComment-358713 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.