# Ordering mysql ouput by row name

**URL:** <https://forum.kirupa.com/t/ordering-mysql-ouput-by-row-name/244512>\
**Category:** Uncategorized\
**Created:** [November 19, 2007, 7:43am UTC](https://forum.kirupa.com/t/ordering-mysql-ouput-by-row-name/244512 "2007-11-19T07:43:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [November 19, 2007, 7:43am UTC](https://forum.kirupa.com/t/ordering-mysql-ouput-by-row-name/244512/1 "2007-11-19T07:43:54Z")

</div>

I have a db of teams and i was wondering how to order them by wins. Most wins at top of the list and fewest at the bottom. I got it to output them in the order they sit in the db but have no idea how to sort them by win/loss .Heres my code

```php

          <?php 
         $place=1;
         $result= mysql_query("SELECT * FROM teams");
             if (!$result){
                 die("Database query failed: " . mysql_error());
            } 
          while ($row = mysql_fetch_array($result)){
                 echo $place++. " ".$row[name]." ".$row[won]."<br />";
          }
           ?>

```

any ideas?
