EVOLUTION-NINJA
Edit File: Country_model.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class country_model extends CI_Model { public function add_country($data) { return $this->db->insert('country_table', $data); } public function get_all_countries() { // Assuming your table is named 'countries' $query = $this->db->get('country_table'); // Check if there are rows in the result if ($query->num_rows() > 0) { // Return the result as an array of objects return $query->result(); } else { // Return an empty array if no rows are found return array(); } } public function getCountryById($countryId) { $query = $this->db->get_where('country_table', array('id' => $countryId)); if ($query->num_rows() > 0) { return $query->row(); } else { return null; } } public function update_country($country_id, $data) { $this->db->where('id', $country_id); return $this->db->update('country_table', $data); } public function delete_country($id) { // Delete a country from the database $this->db->where('id', $id); $this->db->delete('country_table'); } //port public function portExists($portName) { $query = $this->db->get_where('ports_of_discharge', array('port_name' => $portName)); return $query->num_rows() > 0; } public function addPort($countryId, $portName) { $data = array( 'country_id' => $countryId, 'port_name' => $portName, ); return $this->db->insert('ports_of_discharge', $data); } // public function getPorts() { // // Assuming you have a database connection configured // $query = $this->db->get('ports'); // $this->db->select('ports.id, ports.country_id, ports.port_name, country_table.country_name'); // $this->db->from('ports'); // $this->db->join('country_table', 'ports.country_id = country_name.id', 'left'); // $query = $this->db->get(); // return $query->result(); // } public function getPorts() { $this->db->select('ports_of_discharge.id, ports_of_discharge.country_id, ports_of_discharge.port_name, country_table.country_name'); $this->db->from('ports_of_discharge'); $this->db->join('country_table', 'ports_of_discharge.country_id = country_table.id', 'left'); // Corrected the join condition $query = $this->db->get(); return $query->result(); } public function getPortById($countryId) { // Retrieve port data from the database based on the provided ID // Replace this with your actual database query $query = $this->db->get_where('ports_of_discharge', array('country_id' => $countryId)); // Return the result as an object return $query->row(); } public function get_port_by_id($port_id) { // Replace 'your_port_table' with your actual table name $query = $this->db->get_where('ports_of_discharge', array('id' => $port_id)); return $query->row(); } public function update_port($portId, $portName) { // Replace 'your_port_table' with your actual table name $data = array('port_name' => $portName); $this->db->where('id', $portId); $this->db->update('ports_of_discharge', $data); } public function deletePort($id) { // Assuming you have a database table named 'ports' // Adjust this query based on your actual table structure $this->db->where('id', $id); $result = $this->db->delete('ports_of_discharge'); return $result; } //product_category public function insertCategory($data) { $result = $this->db->insert('product_category', $data); // Print the last executed query for debugging // echo $this->db->last_query(); return $result; } public function getProducts() { // Assuming you have a table named 'products' in your database $query = $this->db->get('product_category'); return $query->result_array(); } public function get_product_by_id($rowId) { // Query the database to get product details based on $rowId // Adjust this query based on your database schema $query = $this->db->get_where('product_category', array('id' => $rowId)); // Return the result as an object return $query->row(); } public function updateProduct($postData) { // Assuming you have a table named 'products' $this->db->where('id', $postData['product_id']); unset($postData['product_id']); // Remove product_id from update data $this->db->update('product_category', $postData); // Check if the update was successful return $this->db->affected_rows() > 0; } public function deleteProduct($productId) { // Assuming you are using CodeIgniter's Active Record for database operations $this->db->where('id', $productId); $this->db->delete('product_category'); // Check the affected rows to determine if the deletion was successful return $this->db->affected_rows() > 0; } }