不复杂的,首先该表格内的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]
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]
解决方案 »
- 请教像微博那样即时显示有新消息的PHP代码逻辑功能如何实现
- 在PHP中,http_post_data和http_put_data的用法(实例)?
- 为什么 http://localhost/index.php 正常 http://localhost下载index.html
- 不明白下面的代码,求解
- 散分啦~~~
- php5.3支持mssql吗
- 传参数
- Oracle的SQL语句问题!在线等,急!
- mysql连接默认的端口是多少?
- php存数据到数据库,echo出来的sql可正常在mysql里执行但是放在php中执行却抱错,求助大神们
- smarty 中include_php 传递参数的问题,请教一下
- 我想调用一周前发布的信息,这样就行了吧
{
$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);
...
如满足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的用法。
SELECT * FROM xxx WHERE country = 'xxx' AND Crop_Type='xxx' AND (Section=1 AND Section=2 ...)
这只是个例子,至于各个Section之间是AND还是OR,得看你的系统的具体要求了。