kvnirvana Posted March 4, 2011 Share Posted March 4, 2011 foreach($db->query("SELECT * FROM company_people WHERE company_id = ".(int) $company_id) as $row) { $r[] = new People($row['people_id'], $row); I want to make this query order by name, how should I do that, can't figure it out Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/229561-order-by-name/ Share on other sites More sharing options...
Adam Posted March 8, 2011 Share Posted March 8, 2011 It's a little messy having the SQL within the function like that, separate it into a variable and you'll probably find it easier to work out the syntax in future. In this case, you just need to re-open the string after the variable and add the order by clause: $sql = "SELECT * FROM company_people WHERE company_id = " . (int) $company_id . " order by name"; [...] Quote Link to comment https://forums.phpfreaks.com/topic/229561-order-by-name/#findComment-1184477 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.