使用多个输入字段搜索oracle数据库

时间:2013-10-15 05:41:12

标签: php oracle

我尝试使用多个输入字段搜索oracle数据库的此代码,以及此代码中的错误以及需要更改的位置plz解释您的代码becoz我是编程中的新手.......谢谢

我的代码:                             

  $cond_string = "";
  if(!empty($_GET['OPRID']))
   {
$cond_string .= " AND OPRID LIKE '%".$_GET['OPRID']."%'";
  }

 if(!empty($_GET['OPRDEFNDESC']))
  {
  $cond_string .= " AND OPRDEFNDESC LIKE '%".$_GET['OPRDEFNDESC']."%'";
   }
   if(!empty($_GET['EMAILID ']))
    {
 $cond_string .= " AND EMAILID  LIKE '%".$_GET['EMAILID']."%'"; 
  }
   if(!empty($_GET['EMPLID']))
   {
$cond_string .= " AND EMPLID LIKE '%".$_GET['EMPLID']."%'";
    }


   $query ="SELECT  * FROM OPERATOR WHERE(OPRID LIKE '%".$_GET["OPRID"]."%'  
        or OPRDEFNDESC LIKE '%".$_GET["OPRDEFNDESC"]."%' or EMPLID LIKE  

         '%".$_GET["EMPLID"]."%'
        or EMAILID LIKE '%".$_GET["EMAILID"]."%') ";
    $objParse = oci_parse ($ora_conn, $query);  
    $objResult = oci_execute ($objParse,OCI_DEFAULT);  
    ?>
      </br> 
    </br> 
    </br> 
     <table width="500" border="1" align="center">  
     <tr>  
      <th width="98"> <div align="center">Operator ID:</div></th>  
   <th width="98"> <div align="center">Operator Name:</div></th>  
    <th width="98"> <div align="center">Person ID:</div></th>  
    <th width="98"> <div align="center">Email ID:</div></th> 
   <th width="98"> <div align="center">Edit:</div></th>   
    </tr> 

     <?  

  while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC)) 
   {  
    ?>  
   <tr>  
     <td><div align="center"><?=$objResult["OPRID"];?></div></td>  
     <td><?=$objResult["OPRDEFNDESC"];?></td>  
    <td><?=$objResult["EMPLID"];?></td>  
    <td><div align="center"><?=$objResult["EMAILID"];?></div></td> 
  <td align="center"><a  href="Optr_Edit.php?OprID=<?=$objResult["OPRID"];?>">Edit</a>    

     </td> 
    </tr>  
   <?  
      }  
      ?>  
    </table>  
  <?  
   oci_free_statement($objParse);
       oci_close($ora_conn); 

     ?>  
     </body>
      </html>

1 个答案:

答案 0 :(得分:2)

<form action="Optr_Search.php" method="get" name="frm" id="frm">
    <table width="500" border="0" align="center">  
        <tr>  
            <th>Operator ID :
            <input name="OPRID" type="text" id="OPRID" value="";>
            </th> 
        </tr>
        <tr>  
            <th>Operator Name :
            <input name="OPRDEFNDESC" type="text" id="OPRDEFNDESC" value="";> 
            </th>
        </tr>
        <tr> 
            <th>Person ID :
            <input name="EMPLID" type="text" id="EMPLID" value="";> 
            </th>
        </tr>
        <tr>  
            <th>Email ID :
            <input name="EMAILID" type="text" id="EMAILID" value="";>  

            </th>  
        </tr>
        <tr>
            <td>
            <input type="submit" value="Search">
            </td>
        </tr>

</table>  
</form>

<强> Optr_Search.php

<?php
//this will append conditions to query..change this $_GET fileds according to ur form credentials and u can use "=" instead of LIKE if u want exct match from ur table
$cond_string = "";
if(!empty($_GET['OPRID']))
{
    $cond_string .= " AND OPRID LIKE '%".$_GET['OPRID']."%'";
}

if(!empty($_GET['OPRDEFNDESC']))
{
    $cond_string .= " AND OPRDEFNDESC LIKE '%".$_GET['OPRDEFNDESC']."%'";
}
if(!empty($_GET['EMAILID ']))
{
    $cond_string .= " AND EMAILID  LIKE '%".$_GET['EMAILID']."%'";  
}
if(!empty($_GET['EMPLID']))
{
    $cond_string .= " AND EMPLID LIKE '%".$_GET['EMPLID']."%'";
}

//here ur query goes..change in query according to ur need
$query ="SELECT  * FROM OPERATOR WHERE 1=1 ".$cond_string.";
?>