Am using php, mysql to retrieve data from my database it is neither displaying error nor giving me the required data.
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);
}
?>
this is what i later did in my function, and it worked...
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"];
}
}
}
you should return the fetched result $query->fetch()