我已經這樣做了近一個月,但我無法弄清楚如何獲取我表中每一行的「細節」。我認爲我的表是foreach。並將其發佈到另一個頁面中。通過點擊第一頁上名爲「Details ...」的鏈接。Codeigniter通過鏈接獲取行詳細信息(foreach)
例如:香港專業教育學院在搜索第一頁,這是結果:
column1 column1 column3 column4 column5 column6
name desc age num add Details...
name desc age num add Details...
當我點擊第一個細節......它會去第二頁和文章名稱,DESC,年齡,NUM,添加到文本框中。相同的第二個細節... 任何幫助將不勝感激。謝謝。
這裏是我的代碼:
我的模型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();
}
}
我控制器的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);
}
}
我看來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_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中。我不能在第一頁的特定鏈接的價值,這是我的代碼上獲得的第一頁,但即時通訊鏈接的價值不是成功的:
控制器: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();
}
非常感謝您的幫助。希望得到一個反饋。 :)
我從你的問題有什麼是你想要得到特定行的細節在詳細信息點擊。因此,您需要將行ID附加到您的詳細信息鏈接,如明智你可以看到另一個頁面上的細節,特定的行。 – Zeeshan 2014-09-06 09:30:47
@Zeeshan,是你的權利。那就是我想要做的,但沒有成功的ATM。我只想點擊那些細節,然後到具有特定行詳細信息的另一頁。 – Klingel 2014-09-08 03:20:12
是的,這就是我建議你將行ID傳遞到另一個頁面,並從數據庫中獲取該ID的詳細信息,並顯示that.if你仍然有疑問讓我知道。 – Zeeshan 2014-09-08 06:09:34