I have a database of a few hundred users, and they are divided into two groups, leader or not leader, by a boolean in the MySQL database. For the members page, I need to show all the leaders in alphabetical order, and then all the non-leaders in alphabetical order. I’m wondering how to do this.
The way that I’ve done it in the past is to query the database twice, one query looking for leaders, and the other for non-leaders, but that seems very inefficient to me. The other way that just occurred to me was to query the database for all all leaders, and then to iterate through the whole lot of them and decide whether or not they should added to the leaders string, or the non-leaders string:
[code=php]
if ($row[‘leaderornot’]==true){
$leader.=’info from leader’;
}
else {
$nonleader.=’info from non-leader’;
}
…
echo $leader,'<hr>’,$nonleader;
So what I’m wondering is, which is more efficient, or is there a third even better way again?