2014-09-06 77 views
0

我已經這樣做了近一個月,但我無法弄清楚如何獲取我表中每一行的「細節」。我認爲我的表是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(); 

} 

非常感謝您的幫助。希望得到一個反饋。 :)

+0

我從你的問題有什麼是你想要得到特定行的細節在詳細信息點擊。因此,您需要將行ID附加到您的詳細信息鏈接,如明智你可以看到另一個頁面上的細節,特定的行。 – Zeeshan 2014-09-06 09:30:47

+0

@Zeeshan,是你的權利。那就是我想要做的,但沒有成功的ATM。我只想點擊那些細節,然後到具有特定行詳細信息的另一頁。 – Klingel 2014-09-08 03:20:12

+0

是的,這就是我建議你將行ID傳遞到另一個頁面,並從數據庫中獲取該ID的詳細信息,並顯示that.if你仍然有疑問讓我知道。 – Zeeshan 2014-09-08 06:09:34

回答

0

我想通了。感謝您的答案,球員特別。

我的模型:

public function get_equipment_id($id) { 

$array = array('id' => $id); 
$this->db->where($array); 
$equipid = $this->db->get('equip'); 
return $equipid->result(); 

} 

我的控制器:

function view_equipment_details($id) 
{ 
$data['equipid'] = $this->model->get_equipment_id($id); 
$this->load->view('auth/view_equipment', $data); 
} 

筆者認爲:

echo "<td>".anchor("auth/view_equipment_details/".$item->id, 'Details...', array('class' => 'detail'))."</td>"; 
3

什麼亂七八糟這裏budy ...

你的問題確實讓人困惑,但我認爲你正在嘗試做一個鏈接:

<?php echo anchor("auth/view_equipment_details/".$item->id, 'Details...', array('class' => 'detail')))?> 

注意:它能夠更好地傳遞一個id在url中(或者可能是slug),但不是字段,因爲您必須使用該id在請求的控制器中執行搜索。

,然後在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應該作爲參數。

+0

加一個有勇氣通讀OP並實際嘗試答案的人。做得好。 – 2014-09-06 16:39:20

+0

@Patricio感謝您的回覆,是啊我的代碼都搞砸了哈哈。我試過你的答案,但它不起作用。第二頁中沒有顯示詳細信息。 – Klingel 2014-09-08 07:12:10

0

通過這種方式,您可以在另一頁上訪問您的個人行詳細信息。

例如,您有page1的表格,其中列出了所有行和鏈接,如您在其他頁面中列出的詳細信息所示。

所以附加ID,以您的詳細信息列在網址中,所以按你的代碼它是這樣的

echo "<td>".anchor("auth/search_details/".$id_of_row, 'Details...', array('class' => 'detail'))."</td>"; 

現在,在您的控制器功能名爲「SEARCH_DETAILS」將是這樣的:

function search_details ($row_id) 
{ 
    //code here to get/fetch row from database using $row_id 
} 

這樣您就可以將特定的行詳細信息傳遞給另一個頁面。

如果您有任何疑問,請告知我們。

+0

我已經在我的鏈接中附加了每行ID這裏echo「​​」.anchor(「auth/view_equipment_details /".$ item-> Column6,'Details ...',array('class'=>'detail')) 「」;但我不知道什麼是我的控制器功能。意思是我不知道要在search_details上放什麼($ row_id):/ – Klingel 2014-09-08 06:48:24

+0

這就是我給你展示的。現在你讓你的函數接受參數了,$ row_id將被傳遞給你的控制器,你可以在函數中訪問它。 例如,將$ row_id傳遞到您的模型以獲取行將是: '$ this-> search_model-> get_row($ row_id)' – Zeeshan 2014-09-08 06:50:57

+0

我做了你的兩個代碼。但是我將在函數search_details中放置什麼。我應該把我以前的代碼? $ data ['equipid'] = $ this-> model-> get_equipment_id(); $ this-> load-> view('auth/view_equipment',$ data);還有我會把我的模型放在什麼位置? – Klingel 2014-09-08 07:36:40