PHP 新手 想问一个站内搜索的有关问题

WBOY
Release: 2016-06-13 13:20:55
Original
809 people have browsed it

PHP 新手 想问一个站内搜索的问题
我刚学PHP 想做一个很简单站内搜索。 页面是这样的:

--------------------------
Pestcide_trade_name: (一个下来菜单)
Company name: (一个下拉菜单)
Active ingredient:(一个下拉菜单)

Application:(一个textarea)
Enviroment:(一个textarea)
-------------------------------------(上面的在数据库的一个表里insecticide, 下面的在表crop里)
Crops: (一个下拉菜单)
REI:(一个下拉菜单)
Note: (一个textarea)

Search button

------------------------------

Pestcide_trade_name和ID 是主键。

数据库一共两张表, 上面5个在表insecticide里,下面三个在crop里。
我想做到的就是 Pestcide_trade_name和crop是必须选的,没选择要给提示要求选择。 其他的条件可选可不选,然后结果就是把所有符合选中条件的结果显示出来放在一个表格里打出来。

我写的search.php:

----------------------------------------------------------------------
 if (isset($_POST['TN'])&&!empty($_POST['TN'])&&isset($_POST['Crops'])&&!empty($_POST['Crops'])){
  $searchp = "select ID, Pestcide_trade_name, Crops from insecticide, crop where insecticide.Pestcide_trade_name='".$_POST['TN']."' and crop.Crops='".$_POST['Crops']."'and insecticide.ID =crop.ID ";

if(isset($_POST['CN'])&&!empty($_POST['CN'])) 
$searchp.="and insecticide.Company_name='".$_POST['CN']."'";
  if(isset($_POST['AI'])&&!empty($_POST['AI'])) 
$searchp.="and insecticide.Active_ingredient='".$_POST['AI']."'";
if(isset($_POST['PPE'])&&!empty($_POST['PPE'])) 
$searchp.="and insecticide.PPE='".$_POST['PPE']."'";


if(isset($_POST['REI'])&&!empty($_POST['REI'])) 
$searchp.="and crop.REI='".$_POST['REI']."'";//and crop.Pestcide_trade_name='".$_POST['TN']."' and crop. ID = insecticide.ID";
   
$resultp=mysql_query($searchp);
   
echo"

";

($rs=mysql_fetch_object($resultp)){
 
echo '';
echo '';  
 
}
echo'
ID Company Name Trade name Active Ingredient PPE Applicators Must Wear Mixers/loaders Must Wear Environmental Hazards CROPS REI
'.$rs->ID.' '.$rs->Company_name.' '.$rs->Pestcide_trade_name.' '.$rs->Active_ingredient.' '.$rs->PPE.'
'.$rs->AMW.'
Copy after login
'.$rs->MMW.'
Copy after login
'.$rs->EH.'
Copy after login
'.$rs->Crops.'
Copy after login
'.$rs->REI.'
Copy after login
';
--------------------------------------------------------------------------
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template