如何使记录可点击

时间:2014-03-04 12:02:49

标签: php codeigniter

如何使我的记录可点击?例如我的记录的名称..所以,当我点击它们时,我将被重定向到一个新的页面,我可以打印该记录及其他信息..这里我的表格看起来像

    <div id="vi">
    <div id = "search_field">
    <?php 
    $search_field = array('name'=>"search_field",'placeholder'=>"Search booking : Type the name of guest.");
    echo form_open('site/view');
    echo form_input($search_field);
    echo form_submit('search',"Search");
    ?>
    </div>

    <?php 
     $this->table->set_heading("Name","Nationality","Contact Number","Number of Guest","Date of Arrival","Package","Other Request","Delete Record","Edit");
    $qry = $this->db->like('name',$search_key)->get('booking');
    if ($qry->num_rows > 0) {
    foreach ($qry->result() as $row) {
      $this->table->add_row($row->name,$row->nationality,$row->contactnum,$row->number_of_guest,$row->date,$row->package,$row->request,anchor('site/delete/'.$row->id, 'Delete'),anchor('site/update/'.$row->id, 'Edit'));
 }
 }
  else{
echo "No records found!";
 }

  echo $this->table->generate();

2 个答案:

答案 0 :(得分:2)

试试这个

<?php 
$this->table->add_row("<a href='yourpage.php?name=$name' target='_blank'>$row->name
</a>",$row->nationality,$row->contactnum,$row->number_of_guest,
$row->date,$row->package,$row->request,anchor('site/delete/'.$row->id,
'Delete'),anchor('site/update/'.$row->id, 'Edit'));
?>

答案 1 :(得分:0)

如果数据来自您的数据库,您将执行类似的操作:

<?php
 $query = "SELECT ..... FROM....";
 $res = mysql_query($query);
// HEADER
$this->table->set_heading("Name","Nationality","Contact Number","Number of Guest","Date of Arrival","Package","Other Request","Delete Record","Edit");

while($res=mysql_fetch_array($res)){
    $id = mysql_fetch_array("id");
    $name = mysql_fetch_array("name");
    $nationnality = mysql_fetch_array("nationnality");
    $guests = mysql_fetch_array("guests");
    $date = mysql_fetch_array("date");
    //...
    $this->table->add_row("<a href='secondPage.php?id=$id'>".$name."<a>",$nationnality,$guests,$date);

}
?>

您在数据库中查询获取信息,并为每个结果创建一个新行。
那么,你需要一个与某些东西相关的链接,以便从其他人那里识别你的行,所以每行都有不同的id。