Mysql比较值

时间:2017-02-28 04:42:48

标签: php mysql

我想从我的下拉列表中获取值并将其与我的departmentId行进行比较,因此在生成报告时,我只需从department表中调用departmendId行。

<div class="form-group category">
        <label for="category">Departamento: </label>
        <select  class="form-control form-element" name='department'>
        <option selected disabled> --Piliin ang Departamento-- </option>
        <h3><optgroup label="ADMINISTRATIVE SERVICES">  
        <option class='drop-down' value='1'> Office of the City Mayor </option> 
        <option class='drop-down' value='2'> Office of the City Administrator </option>                                         
        <option class='drop-down' value='3'> Human Resources Management Office </option>                                                
        <option class='drop-down' value='4'> Central Records Management Office </option>                                                    
        <option class='drop-down' value='5'> General Services Office </option>
        <option class='drop-down' value='6'> Procurement Office  
    </option>   
        <option class='drop-down' value='7'> Public Information Office </option>
        <option class='drop-down' value='8'> Anti-Graft Board  </option>
        </optgroup>
        </select>
        </div>

//这是我的下拉列表

 if (isset($_GET['department']))
        {
            $department=$_GET['department'];
                              }

//这是我从下拉列表中获取值的代码

 $depId = "SELECT FROM departments WHERE 'departmentId' = $department";
  $result = mysql_query($depId);
  if($department == $result) {
   $query = "INSERT INTO complain (department,name,address,barangay,complainee,subject,message) VALUES('$result','$fullname','$address','$barangay','$complainee','$subject','$message')";
   $res = mysql_query($query);
   }

//这是我的代码,用于比较我的下拉列表到departmentId行的值,departmentId的值必须在投诉表的部门行中,当我查看我的投诉表时,部门行显示什么都没有。

3 个答案:

答案 0 :(得分:0)

您的查询中存在问题,请更改您的选择查询,如下所示:

SELECT * 
FROM departments 
WHERE departmentId = $department;

答案 1 :(得分:0)

更改此行:

$depId = "SELECT FROM departments WHERE 'departmentId' = $department";

$depId = "SELECT * FROM departments WHERE departmentId = '$department'";

使用

var_dump(...);die();

为您的代码的每个级别提供便利。例如:

 $depId = "SELECT * FROM departments WHERE 'departmentId' = $department";
 var_dump($depId);die();

答案 2 :(得分:0)

第一个正确的SQL Exec查询必须是

SELECT

然后,您需要使用SELECT * FROM departments WHERE departmentId = $department; 语句之一获取departmentId的值,最后将其与mysqli_fetch()进行比较。如下所示。

$department