public function get_all() { $enquiry_list = array(); $this->db->connect(); //Query $sql = "SELECT * FROM tbl_enquiries"; //run query $result = $this->db->fetch_query($sql); while ($row = $result->fetch_assoc()) { $enquiry = new Enquiry(); $enquiry->set_id($row['id']); $enquiry->set_company_name($row['company_name']); $enquiry->set_first_name($row['first_name']); $enquiry->set_last_name($row['last_name']); $enquiry->set_email($row['email']); $enquiry->set_message($row['message']); $enquiry->set_contact_no($row['contact_no']); $enquiry->set_subject($row['subject']); $enquiry->set_enquiry_date($row['enquiry_date']); $enquiry->set_is_read($row['is_read']); array_push($enquiry_list, $enquiry); } $this->db->close(); return $enquiry_list; }
private function _map_posted_data() { $enquiry = new Enquiry(); $enquiry->set_company_name($_POST['company_name']); $enquiry->set_first_name($_POST['first_name']); $enquiry->set_last_name($_POST['last_name']); $enquiry->set_email($_POST['email']); $enquiry->set_contact_no($_POST['contact_no']); $enquiry->set_subject($_POST['subject']); $enquiry->set_message($_POST['message']); $enquiry->set_enquiry_date(date('Y-m-d H:i:s')); return $enquiry; }
public function get_all($order_by = null) { $enquiry_list = array(); $this->db->connect(); $sql = "SELECT * from tbl_enquiries"; if (!is_null($order_by)) { $sql = $sql . " ORDER BY " . $order_by; } $result = $this->db->fetchQuery($sql); while ($row = $result->fetch_assoc()) { $enquiry = new Enquiry(); $enquiry->set_id($row['id']); $enquiry->set_company_name($row['company_name']); $enquiry->set_first_name($row['first_name']); $enquiry->set_last_name($row['last_name']); $enquiry->set_email($row['email']); $enquiry->set_contact_no($row['contact_no']); $enquiry->set_enquiry_date($row['enquiry_date']); $enquiry->set_subject($row['subject']); $enquiry->set_message($row['message']); $enquiry->set_is_read($row['is_read']); $enquiry_list[] = $enquiry; } $this->db->close(); return $enquiry_list; }
<?php include_once "../config.php"; include_once ROOT_PATH . "system/models/enquiry.class.php"; include_once ROOT_PATH . "system/repository/enquiry_repository.class.php"; if (!isset($_POST['submit'])) { header("location:index.php"); } $enquiry = new Enquiry(); $enquiry->set_company_name($_POST['company_name']); $enquiry->set_first_name($_POST['first_name']); $enquiry->set_last_name($_POST['last_name']); $enquiry->set_email($_POST['email']); $enquiry->set_contact_no($_POST['contact_no']); $enquiry->set_subject($_POST['subject']); $enquiry->set_message($_POST['message']); $enquiry->set_enquiry_date(date('Y-m-d H:i:s')); $enquiry_repository = new EnquiryRepository(); $result = 0; if (isset($_POST['id']) && $_POST['id'] == '') { $result = $enquiry_repository->insert($enquiry); } else { $enquiry->set_id($_POST['id']); $result = $enquiry_repository->update($enquiry); } if ($result > 0) { header("location:index.php?success=true"); } else { header("location:add.php?error=true"); } exit;