Alphabetical order no While?

1

I have a listing of teachers on a website, and it is being printed in chronological order, and I wanted to put it alphabetically.

Follow the code below:

<div class="row">
    <ul class="team-list sort-destination appear-animation animated fadeInUp appear-animation-visible" data-appear-animation="fadeInUp" data-appear-animation-delay="50" data-sort-id="team">
        <? while ($p = $prof->fetch(PDO::FETCH_ASSOC)){?>
            <li class="col-md-3 col-sm-6 col-xs-12 isotope-item <?=str_replace(' ', '-', tirarAcentos($p['materia']));?>">
                <div class="team-item thumbnail">
                    <p class="thumb-info team">
                        <img class="img-responsive" alt="" src="http://editoraopirus.com.br/uploads/<?=$p['unidade'];?>/professores/<?=$p['url_foto'];?>"><spanclass="thumb-info-title">
                            <span class="thumb-info-inner"><?=$p['nome'];?></span>
                            <span class="thumb-info-type"><?=$p['materia'];?></span>
                        </span>
                    </p>
                </div>
            </li>
        <? }?>
    </ul>
</div>
    
asked by anonymous 01.09.2017 / 13:58

1 answer

3

If you can not change your SQL query (recommended)

SELECT * FROM 'tabela' ORDER BY 'nome' ASC

8.2.1.13 ORDER BY

-

You can use the sort ()     

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "\n";
}

?>

It will be printed:

fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
    
01.09.2017 / 14:27