0
我有一个数据库表中有11个实体的MySQL。当用户首次搜索一个项目时,我的代码显示5个实体,然后有一个链接供用户点击以查看该项目的更多信息。当用户点击链接时,应该引导他们进入一个新页面,其中包含有关基于itemID点击的项目的信息。我不知道如何将实体的itemID传递给控制器。请帮忙! 这里是我的代码: 位指示:显示关于一个项目的更多信息php codeigniter
<?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();
}}?>
查看:
<body>
<h1><center>Item List</center></h1>
<hr>
<div class="container">
<form method="post" action="<?php echo site_url('itemView/index'); ?>">
<table>
<tr>
<th><input type="radio" name="chk"></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($results as $rows):?>
<tr>
<td><input type="radio" name="chk"></td>
<td><?php echo $rows['inventoryID'] ?></td>
<td><?php echo $rows['masterCode'] ?></td>
<td><?php echo $rows['itemName'] ?></td>
<td><?php echo $rows['colorName'] ?></td>
<td><?php echo $rows['location'] ?></td>
<td><a href="<?php echo site_url('itemView/viewItems'); ?>">click to view more information</a></td>
</tr>
<?php endforeach; ?>
</table>
</form>
</div></body>
信息查看ItemView控件
<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>