1

我有一个搜索页面,其中包括三种类型的搜索,允许用户选择其中一种。

第二种类型包含一个下拉列表,允许用户选择存储在数据库中的值之一。

  • 类型 1:按最新
  • 类型 2:通过专业化
  • 类型 3:按名称

专业表:

  • 专业化_id
  • 专业化名称

成员表:

  • 用户身份
  • 专业化>>通过 id 与专业化表相关

第一种类型正常工作,但第二种类型不显示与所选专业相关的专业,但它显示所有用户及其专业。

我想过滤并仅显示具有所选专业化的用户。

谁能帮我 ??

搜索.php

//************for specialization droplist***************************//
function specializationQuery(){

$specData = mysql_query("SELECT * FROM specialization");

  while($recordJob = mysql_fetch_array($specData)){

     echo'<option value="' . $recordJob['specialization_id'] .  '">' . $recordJob['specialization_name'] . '</option>';

  }


}
$outputlist = "";
//**********search by new***************************************//
if(isset($_POST['searchbynew']))
{
    $listnew = $_POST['searchbynew'];
    $sql = mysql_query("SELECT * FROM members WHERE registered_date!='' ORDER BY registered_date DESC  ")or die((mysql_error("Error in quering new members List")));

    while($row = mysql_fetch_array($sql))
    {
        $row_id = $row['user_id'];
        $row_first_name =  $row['first_name'];
        $row_last_name =  $row['last_name'];
        $row_birthdate =  $row['birth_date'];
        $row_registered_date = $row['registered_date'];

         ////***********for the upload image*************************//
       $check_pic="members/$row_id/image01.jpg";
       $default_pic="members/0/image01.jpg";
       if(file_exists($check_pic))
       {
           $user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
       }
       else
       {
           $user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
       }

        $outputlist.='
   <table width="100%">
               <tr>
                  <td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
                  <td width="14%"><div  align="right">Name:</div></td>
                  <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
                  </tr>

                  <tr>
                    <td><div align="right">Birth date:</div></td>
                    <td>'.$row_birthdate.'</td>
                  </tr>
                  <tr>
                   <td><div align="right">Registered:</div></td>
                   <td>'.$row_registered_date.'</td>
                  </tr>
                  </table>
                  <hr />
          ';


    }//close while
}

if(isset($_POST['searchbyspec']))
{
    $selectedSpec = $_POST['specialization'];
    $sql = mysql_query("SELECT user_id,first_name, last_name, birth_date, registered_date, specialization_name 
                        FROM members u INNER JOIN  specialization s 
                        ON u.specialization = s.specialization_id") or die(mysql_error("Error: quering thespecialization"));

    while($row = mysql_fetch_array($sql))
    {
        $row_id = $row['user_id'];
        $row_first_name =  $row['first_name'];
        $row_last_name =  $row['last_name'];
        $row_birthdate =  $row['birth_date'];
        $row_registered_date = $row['registered_date'];
        $row_spec = $row['specialization_name'];

        ////***********for the upload image*************************//
       $check_pic="members/$row_id/image01.jpg";
       $default_pic="members/0/image01.jpg";
       if(file_exists($check_pic))
       {
           $user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
       }
       else
       {
           $user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
       }

        $outputlist.='
   <table width="100%">
               <tr>
                  <td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href =              "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
                  <td width="14%"><div  align="right">Name:</div></td>
                  <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
                  </tr>

                  <tr>
                    <td><div align="right">Birth date:</div></td>
                    <td>'.$row_birthdate.'</td>
                  </tr>
                  <tr>
                   <td><div align="right">Registered:</div></td>
                   <td>'.$row_registered_date.'</td>
                  </tr>

                  <tr>
                   <td><div align="right">Registered:</div></td>
                   <td>'.$row_spec.'</td>
                  </tr>
                  </table>
                  <hr />
          ';


    }

}
?>
4

0 回答 0