按字段标题php mysql排序数据

时间:2011-11-02 07:53:44

标签: 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>

1 个答案:

答案 0 :(得分:1)

我想,您正在寻找ORDER BY

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