a.php
 <form action="b.php " method="get" name="form2"  >
     <table>     
 <input name="township" type="text" size="8">         
 <input name="range" type="text" size="8">
 <input name="dir" type="text" size="8">
 <input name="section" type="text" size="8">
<input name="submit" type="submit" value="submit">
    </table>
   </form>
b.php
<?php
$map=array('Township'=>'township','Range'=>'range', 'dirid'=>'dir', 'Section'=>'section'); $where=''; $and=''; foreach ($map as $k => $v) { if (!empty($_GET[$v])) { $where.=$and.$k.'='.$_GET[$v]; $and=' and '; } } $query =" SELECT Business_Owner,Business_Name,Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage,County FROM pesticide_sensitive_crop"; if (!empty($where)) { $query.=' WHERE '.$where; }?> 如上代码,我想让从数据库中搜索出的数据按照数据库中的字段County, Township, Range升序排列, b.php中的代码应该怎么改啊,谢谢大家了。

解决方案 »

  1.   

    在SQL语句后边加上:
    order by County,Township,Range就没问题了
      

  2.   

    B.php中$query =" SELECT Business_Owner,Business_Name,Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage,County FROM pesticide_sensitive_crop";//这句改为$query =" SELECT Business_Owner,Business_Name,Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage,County FROM pesticide_sensitive_crop order by County,Township,Range  asc";
      

  3.   

    [/Quote]要看请LZ的说明,他想要升序排列,所以最好加上order by County,Township,Range asc
      

  4.   

    不加asc或者desc,默认是升序asc的
      

  5.   

    用order by, 可是我按照Township 排序,出来的顺序怎么是这个样子的(如下:)
    1,10,11,12,13,14,15,16,17,18,2,21,22,23,24,25,26,27,28,29,3
    31,32,33,35,36,4,5,6,7,8急,有哪位帮帮我,多谢了