2017-01-02 73 views
-1

我使用php,mysql從我的數據庫檢索數據,它既不顯示錯誤也不給我所需的數據。我的查詢沒有顯示任何東西

public function last_material_code($department_id){ 
    $query = $this->db->prepare("SELECT material_code FROM materials_tbl WHERE dept_id = $department_id"); 
    return $query -> execute(); 
} 

<?php 
include_once ('select.class.php'); 

if(isset($_POST['department_id'])){ 
    $department_id = $_POST['department_id']; 

    $object = new select_class($DB_con); 
    $object -> last_material_code($department_id); 
} 
?> 
+0

公共職能last_material_code($部門標識){$ query = $ this-> db-> prepare(「SELECT material_code FROM materials_tbl WHERE dept_id = $ department_id」); return $ query - > execute(); } –

+0

你在哪裏/如何迴應? –

+0

那是因爲你沒有處理你的查詢生成的結果集。 **閱讀手冊** – RiggsFolly

回答

0

這是我在我的功能後來才和它的工作...

public function last_material_code($department_id){ 
$query = $this->db->prepare("SELECT material_code FROM materials_tbl 
    WHERE dept_id = $department_id ORDER BY Id DESC LIMIT 1"); 
    $query -> execute(); 
    if ($query){ 
     while($row=$query->fetch(PDO::FETCH_ASSOC)){ 
      echo $row["material_code"]; 
     } 
    } 
} 
0

你應該返回所取得的結果$query->fetch()