Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示有关项目php codeigniter的更多信息_Php_Mysql_Codeigniter - Fatal编程技术网

显示有关项目php codeigniter的更多信息

显示有关项目php codeigniter的更多信息,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在mysql中有一个数据库表,它有11个实体。当用户第一次搜索项目时,“我的代码”显示5个实体,然后有一个链接供用户单击以查看有关该项目的更多信息。当用户单击该链接时,它将引导他们进入一个新页面,其中包含基于itemID单击的项目的信息。我不知道如何将实体的itemID传递给控制器。请帮忙! 这是我的密码: 控制者: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class ItemView

我在mysql中有一个数据库表,它有11个实体。当用户第一次搜索项目时,“我的代码”显示5个实体,然后有一个链接供用户单击以查看有关该项目的更多信息。当用户单击该链接时,它将引导他们进入一个新页面,其中包含基于itemID单击的项目的信息。我不知道如何将实体的itemID传递给控制器。请帮忙! 这是我的密码: 控制者:

 <?php defined('BASEPATH') OR exit('No direct script access allowed');
class ItemView extends CI_Controller {
public function __construct(){
    parent::__construct();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->model('itemModal');
}
public function index(){
    $this->load->view('base');
    $this->load->view('searchResult');
}
public function viewItems(){
    //trying to get the id of the clicked item
    $id = $this->input->post($rows['inventoryID']);
    $data['results'] = $this->itemModal->get_items($id);
    $this->load->view('base.php',$data);
    $this->load->view('itemview.php',$data);
}
}
?>

型号:

<?php 
class ItemModal extends CI_Model {
function __construct(){
    parent::__construct();
}
function get_items($id){
    $this->db->select('*');
    $this->db->like('inventoryID',$id);

    // Execute the query.
    $query = $this->db->get('inventory');

    // Return the results.
    return $query->result_array();

}}?>

视图:


项目表

项目视图的视图

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/search.css">
    <title>Item Information Page</title>
</head>
<body>
    <h1><center>Item Information</center></h1>
    <hr>
    <div class="container">

    </div>
    <!-- End of Container -->
</body><br><br>
</html>


你需要像这样改变 控制器

<?php defined('BASEPATH') OR exit('No direct script access allowed');
    class ItemView extends CI_Controller {
        public function __construct(){
            parent::__construct();
            $this->load->helper(array('url','form'));
            $this->load->model('itemModal', 'model_items');
        }

        public function index(){
            //get all items from db to display basic info in form
            $data['items']=$this->model_items->get_all();
            $this->load->view('base');
            $this->load->view('searchResult', $data);
        }

        //get the specific item to be updated
        public function updateItem( $id ){
            $data['results'] = $this->model_items->get_item_by_id($id);
            $this->load->view('base',$data);
            //viw with inpus form to change the info and send to controller to be updated
            $this->load->view('itemview',$data);
        }

        //get all items to be updated
        public function updateItems(){
            foreach($this->input->post() as $item => $value){
                ${$item} = $value;
            }

            //here you need to add logic to make wherever you want with all items selected in form
        }
    }

<?php defined('BASEPATH') OR exit('No direct script access allowed');
    class ItemView extends CI_Controller {
        public function __construct(){
            parent::__construct();
            $this->load->helper(array('url','form'));
            $this->load->model('itemModal', 'model_items');
        }

        public function index(){
            //get all items from db to display basic info in form
            $data['items']=$this->model_items->get_all();
            $this->load->view('base');
            $this->load->view('searchResult', $data);
        }

        //get the specific item to be updated
        public function updateItem( $id ){
            $data['results'] = $this->model_items->get_item_by_id($id);
            $this->load->view('base',$data);
            //viw with inpus form to change the info and send to controller to be updated
            $this->load->view('itemview',$data);
        }

        //get all items to be updated
        public function updateItems(){
            foreach($this->input->post() as $item => $value){
                ${$item} = $value;
            }

            //here you need to add logic to make wherever you want with all items selected in form
        }
    }
<?php 
    class ItemModal extends CI_Model {
        function get_all(){
            return $this->db->get('inventory')->result();
        }

        function get_item_by_id($id){
            return $this->db->get_where('inventory', array('id' => $id))->row();
        }
    }
<form method="post" action="<?= site_url('itemView/updateItems'); ?>">
            <table>
                <tr>
                    <!-- select one or more items to be updated bach -->
                    <th><input type="checkbox" name="chk" value="<?= $rows->inventoryID ?>"></th>
                    <th>Inventory ID</th>
                    <th>Master Code</th>
                    <th>Item Name</th>
                    <th>Color Name</th>
                    <th>Location</th>
                    <th>Link to more information</th>
                </tr>
                <?php foreach($itemsas $rows):?>
                <tr>
                    <td><input type="radio" name="chk"></td>
                    <td><?= $rows->inventoryID ?></td>
                    <td><?= $rows['masterCode'] ?></td>
                    <td><?= $rows['itemName'] ?></td>
                    <td><?= $rows['colorName'] ?></td>
                    <td><?= $rows['location'] ?></td>
                    <!-- update specific item -->
                    <td><a href="<?= site_url('itemView/updateItem/'.$rows->inventoryID ); ?>">click to view more information</a></td>
                </tr>
                <?php endforeach; ?>
                <tr>
                    <td>Update all items selected</td>
                    <td><input type="submit" value="Update"></td>
                </tr>
            </table>
     </form>