从<a href=""> for it&#39;s content to be visible on another page with Code Igniter

时间:2017-01-03 17:23:07

标签: php html codeigniter

I am completely new to Code Igniter, and heres my issue:

I am making a Cinema Website, and im trying to get the all of the movies resume in one page, for example, when i pick a movie on the index, it should open me a new link that gives me the movie details that i got on my database.

This is the php from the index Filmes

           <div id="films-tab">
                       <?php
          $lista = $this->db->get('filme');
          foreach($lista->result() as $row) {
    ?>
            <li><a href="<?php echo site_url('briefing');?>"><?php echo        $row->Nome; ?></a></li>

             <?php
                  }
                ?>
             </div>
          </ul>
          </li>

This is the php for the "briefing page"

<link href="assets/recursos/outro.css" rel="stylesheet">
<div class="container-fluid">
<?php
          $query = $this->db->get_where('filme', ['id' => $id]);
          $lista = $this->db->get('filme');
          foreach($lista->result() as $row) {
          $row = $query->first_row();

    ?>
 <img style="margin-right:20px; border:5px solid white; width:320px;     height:468px;"src="<?php echo 'assets/recursos/images/'.$row->Capa; ?>">
  <?php
                  }
                ?>
  </div>

I know the code to show only 1 key in the briefing.php is wrong, but i have no clue how to get it to work, can someone help me?

1 个答案:

答案 0 :(得分:1)

将url中的id作为参数传递,并从该id的数据库中获取数据。

在索引页的网址中传递ID

<div id="films-tab">
                       <?php
          $lista = $this->db->get('filme');
          foreach($lista->result() as $row) {
    ?>
            <li><a href="<?php echo site_url('briefing/'.$row->id);?>"><?php echo        $row->Nome; ?></a></li>

             <?php
                  }
                ?>
             </div>
      </ul>
      </li>

并在简报页面中从网址获取ID

<link href="assets/recursos/outro.css" rel="stylesheet">
<div class="container-fluid">
<?php
          $id = $this->uri->segment(2);
          $query = $this->db->get_where('filme', ['id' => $id]);
          $lista = $this->db->get('filme');
          foreach($lista->result() as $row) {
          $row = $query->first_row();

    ?>
 <img style="margin-right:20px; border:5px solid white; width:320px;     height:468px;"src="<?php echo 'assets/recursos/images/'.$row->Capa; ?>">
  <?php
                  }
                ?>
  </div>