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"
| ID |
Company Name |
Trade name |
Active Ingredient |
PPE |
Applicators Must Wear |
Mixers/loaders Must Wear |
Environmental Hazards |
CROPS |
REI |
";($rs=mysql_fetch_object($resultp)){ echo '
| '.$rs->ID.' |
'.$rs->Company_name.' |
'.$rs->Pestcide_trade_name.' |
'.$rs->Active_ingredient.' |
'.$rs->PPE.' | ';echo '
'.$rs->AMW.' |
'.$rs->MMW.' |
'.$rs->EH.' |
'.$rs->Crops.' |
'.$rs->REI.' |
'; } echo'
';
--------------------------------------------------------------------------