排序数据字段标题PHP mysql


sort data by field heading php mysql

我有一个数据库有两张桌子。正确获取数据的sql查询。我想通过在文本框中键入表格标题来排序字段数据,然后在表脚中单击。多谢

<table border="0" cellpadding="0" cellspacing="0" width="50%">
    <thead>
        <tr>
           <th class="capt" colspan="6">Available Projects</th>
        </tr>
        <tr>         
                    <th>Select</th>
                    <th>Project</th>
                    <th>Crawler</th>
                    <th>Description</th>                        
                    <th>Status</th>
                    <th>Action</th>
         </tr>
    </thead>
    <tbody>
    <?php
    include(dirname(__file__)."/includes/dbConn.php");  
            $result = mysql_query("SELECT *, ( SELECT name FROM projects WHERE projects.id = crawlers.pid ) AS pname FROM `crawlers`", $appConn);
                while($row = mysql_fetch_array($result))
                  {
?>
            <tr id="crawler_<?php echo $row['id']; ?>">                        
                    <td>
                        <input  value="" id="check" type="checkbox"> 
                        <input id="crawler_id_<?php echo $row['id']; ?>" type="hidden" value="<?php $row['id']; ?>" />  <!-- crawler id -->
                    </td>
                    <td><?php echo $row['pname']; ?></td>
                    <td><?php echo $row['name']; ?></td>
                    <td>username@domain.com</td>                        
                    <td>Enabled</td>
                    <td><a class="edit" href="#">edit</a><a class="add" href="#">run</a><a class="delete" href="#">delete</a></td>
            </tr>
           <?php  } ?>
    </tbody>
     <tfoot>
            <tr>
                    <th colspan="6"> Sort Fields by <input value="type here" id="field" type="text"> <a href="#" class="add">Go</a> </th>
            </tr>
     </tfoot>

</table>

我想你是在找ORDER BY

查看MySQL文档关于SELECT语法:http://dev.mysql.com/doc/refman/5.0/en/select.html