我已经这样做了将近一个月,但我无法弄清楚如何获取表格中每一行的“详细信息”。在我看来,我的表是foreach。并将其发布在另一页中。通过单击第一页上名为“详细信息...”的链接。
例如:我在第一页搜索,结果如下:
column1 column1 column3 column4 column5 column6
name desc age num add Details...
name desc age num add Details...
当我单击第一个详细信息时...它会转到第二页并将帖子名称、描述、年龄、编号添加到文本框中。和第二个细节一样... 任何帮助将不胜感激。谢谢。
这是我的代码:
我的模型 model.php - 这是我在数据库表中搜索数据的代码
public function search_equip() {
if ($this->input->post('category') == "All")
{
$match = $this->input->post('search');
$array = array('column1' => $match);
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Appliance")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Appliance");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Furniture")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Furniture");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
elseif ($this->input->post('category') == "Equipment")
{
$match = $this->input->post('search');
$array = array('column1' => $match, 'category' => "Equipment");
$this->db->like($array);
$query = $this->db->get('equip');
return $query->result();
}
}
我的 Controller search.php - 我的代码设置规则
function search_equipment()
{
//If searchbox is empty
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('search', 'Search', 'required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('auth/index', 'refresh');
}
else
{
$data['query'] = $this->model->search_equip();
$this->load->view('auth/search_view_equipment', $data);
}
}
我的 View search_view_equipment.php - 这是我搜索数据并显示每行链接的结果
<?php foreach($query as $item):?>
echo "<tr>";
echo "<td>".<?= $item->Column1 ?>."</td>";
echo "<td>".<?= $item->Column2 ?>."</td>";
echo "<td>".<?= $item->Column3 ?>."</td>";
echo "<td>".<?= $item->Column4 ?>."</td>";
echo "<td>".<?= $item->Column5 ?>."</td>";
echo "<td>".anchor("auth/view_equipment_details/".$item->Column6, 'Details...', array('class' => 'detail'))."</td>";
echo "</tr>";
<?php endforeach;?>
我的第二个 View view_equipment.php - 这是发布来自第一页(特定行)的数据的地方 注意:这个 td 是输入的,我不知道如何使用输入在这里制作代码 :)
<?php foreach($equipid as $item):?>
echo "<tr>";
echo "<td>".<?= $item->Column1 ?>."</td>";
echo "<td>".<?= $item->Column2 ?>."</td>";
echo "<td>".<?= $item->Column3 ?>."</td>";
echo "<td>".<?= $item->Column4 ?>."</td>";
echo "<td>".<?= $item->Column5 ?>."</td>";
echo "<td>".anchor("auth/view_equipment_details/".$item->Column6, 'Details...', array('class' => 'detail'))."</td>";
echo "</tr>";
<?php endforeach;?>
是否可以获取该行的全部数据并将其显示在另一页中?具体来说,我对我要做什么感到困惑,因为该表在 foreach 中。我无法在第一页中获取特定链接的值,这是我在第一页中获取链接值的代码,但我没有成功:
Controller :auth.php
function view_equipment_details()
{
$data['equipid'] = $this->model->get_equipment_id();
$this->load->view('auth/view_equipment', $data);
}
模型:在model.php中添加
public function get_equipment_id() {
$match = $this->input->post(); //This line is where i want to put the specific links ( any links that i click in first page) VALUE or NAME or whatsoever that is EXACTLY THE SAME AS THE ID OF THAT ROW I WILL CLICK to search using (next line): all i need is the value equal to the id of a row in table in database.
$array = array('id' => $match);
$this->db->where($array);
$equipid = $this->db->get('equip');
return $equipid->result();
}
提前感谢您的帮助。希望得到反馈。 :)
最佳答案
伙计,这里真是一团糟......
你的问题真的很困惑,但我认为你是想建立一个链接:
<?php echo anchor("auth/view_equipment_details/".$item->id, 'Details...', array('class' => 'detail')))?>
注意:最好在 url 中传递一个 id(或者可能是一个 slug),而不是一个字段,因为您必须使用该 id 在请求的 Controller 中进行搜索。
然后在 AuthController 中调用 view_equipment_details 的函数:
public function view_equipment_details($id){
$this->data['equipment'] = $this->db->where('id', $id)->get('table_name')->row();
$this->load->view(auth/view_equipment', $this->data)
你正试图从邮寄中得到一些东西,而这与邮寄无关。 id 应该作为参数出现。
关于php - Codeigniter 通过链接获取行详细信息(foreach),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25698772/