不复杂的,首先该表格内的Country和Crop_Type应该是属于普通的varchar类型数据吧。
Section,Township和Range是其他表格的键值么?那就可以做查询表单了的:<form action="search.php" method="post">
    <input type="text" name="country" />
    <input type="text" name="crop_type" />
    <select name="section">
        <option value="0">All</option>
        .... PHP Script ....
    </select>
    <select name="township">
        <option value="0">All</option>
        .... PHP Script ....
    </select>
    <select name="range">
        <option value="0">All</option>
        .... PHP Script ....
    </select>
    <input type="submit" name="search" value="Search" />
</form>PHP Script的位置插入读取所有Section,Township和Range的值的PHP代码。这个很简单的吧。然后就是接受查询表单发送的数据,如果两个文本框内有数据,就添加查询条件
[code=PHP]
if($_POST['country'] != '')
    $sql .= 'AND ( country LIKE \'%'.$_POST['country'].'\' OR country LIKE \'%'.$_POST['country'].'%\' OR country LIKE \''.$_POST['country'].'%\')';
至于下拉菜单,如果返回的值不等于0,那就添加查询条件,原理差不多。
[/code]

解决方案 »

  1.   

    如果查询条件不为空,就将其放入数组.呵呵.function __getFilterStr($arrFilter = array())
    {
    $strFilter = ""; foreach($arrFilter as $key => $value)
    {
    if($strFilter != "")  
    $strFilter .= " AND ";
    else 
    $strFilter .= " WHERE ";

    if(!strpos($value, ')'))
    {
    $strFilter .= sprintf(" %s '%s' ", $key, $value);
    }
    else 
    {
    $strFilter .= sprintf(" %s %s ", $key, $value);
    }
    }  
    return $strFilter;
    }
       
       function __getFieldStr($arrField = array())
       {
        $strField = "";
        foreach($arrField as $key => $value)
        {
        if($strField != "")  
        $strField .= " , ";
        $strField .= sprintf(" %s ", $value);
        }  
       
        if($strField == "") $strField = "*";
        return $strField;
       }$arrField = array('id', 're', 'blog');
    $arrFilter = array('ischeck='=>1);
    $strFilter = $this->__getFilterStr($arrFilter);
    $strField  = $this->__getFieldStr($arrField);
    $sql = sprintf("SELECT %s FROM re  %s ", $strField, $strFilter);
    ...
      

  2.   

    lz整理下思路,其实不是很复杂
    如满足county,  crop_type的查询结果,或County, Crop_Type,Section的查询结果,或同时满足以上所有字段条件的查询结果,怎么做啊?SELECT * FROM WHERE (County='你的条件' AND crop_type='你的条件')
    OR (County='你的条件' AND Crop_Type='你的条件' AND Section='你的条件') OR
    (County='你的条件' AND Crop_Type='你的条件' AND Section='你的条件' AND Township='你的条件' AND Range='你的条件' )最主要是and 和or的用法。
      

  3.   

    我明白了,可是有一个问题,就是我section, township 和range下拉表里头的查询条件是从值1到36或60,难道我要写36次(County='你的条件' AND Crop_Type='你的条件' AND Section='你的条件')这个语句吗? 比如:(County='Adam' AND Crop_Type='Grapes' AND Section='1'), (County='Adams' AND Crop_Type='Grapes' AND Section='2')……一直到(County='Adams' AND Crop_Type='Grapes' AND Section='36'),是这样吗??
      

  4.   

    得看具体情况,如果你要查询的对象有可能同时符合多个Section,那就给你的select下拉菜单做多选了。然后在生成的SQL里面就是:
    SELECT * FROM xxx WHERE country = 'xxx' AND Crop_Type='xxx' AND (Section=1 AND Section=2 ...)
    这只是个例子,至于各个Section之间是AND还是OR,得看你的系统的具体要求了。