CanMan2004 Posted July 1, 2006 Share Posted July 1, 2006 Hi allI have a search form on my website which lets you search for a buddy, the search can be proformed as a name search using there first name, for exampleDavidThe form then goes to the php page and does a query on what has been typed in, it then sorts the results by the persons surname, for exampleDavid AdamsDavid HolmesDavid WaferryThe query I currently perform is[code]$usql = "SELECT * FROM users WHERE `firstname` = '$fname' ORDER BY surname ASC";$ushow = @mysql_query($usql,$connection) or die(mysql_error());while ($urows = mysql_fetch_array($ushow)) {print $urows['firstname'];print " ";print $urows['surname'];print "<br><br>";}[/code]What I want to now do is to offer a surname search box on the same form, what should happen when someone sdoes a search under firstname and surname it would return back all results that match JUST the firstname (like it currently does). What I want to do though, it to show the people who matched the surname at the top of the results and then show just the people who matched the firstname below.The firstname input box on the search form is called "firstname" and the surname one which I want to add will be called "surname".Is this at all possible?Loads of thanks in advanceEd Quote Link to comment https://forums.phpfreaks.com/topic/13404-php-order-by-help/ Share on other sites More sharing options...
Barand Posted July 1, 2006 Share Posted July 1, 2006 [code]SELECT firstname, lastname, IF(lastname='$lastname' , 0 ,1) as seq FROM usersWHERE firstname='$firstname' OR lastname='$lastname'ORDER BY seq, lastname, firstname[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13404-php-order-by-help/#findComment-51752 Share on other sites More sharing options...
CanMan2004 Posted July 1, 2006 Author Share Posted July 1, 2006 thank you a million times over Quote Link to comment https://forums.phpfreaks.com/topic/13404-php-order-by-help/#findComment-51756 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.