将数据库中的值传递给用户上传的HTML

时间:2017-05-21 16:01:49

标签: php mysql codeigniter

更新了当前的代码*

我想我会就我的问题请你帮忙。

我想知道如何更换一列中包含的内容,并将另一列的值与其自身一起取出。

我有以下代码,

<table id="example1" class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>Template</th>
      <th>SaleID</th>
      <th>Description</th>
      <th>Title</th>
      <th>Price</th>
      <th>Status</th>
      <th>User Action</th>
    </tr>
  </thead>
  <tbody>
    <?php
     $res = $MySQLiconn->query("SELECT * FROM crud WHERE uid='{$_SESSION['userSession']}' ORDER BY id DESC");
     while($row=$res->fetch_array())
      {
      ?>
    <tr>
      <td><!-- THIS COL WILL BE HTML CONTENT A USER UPLOADED ALREADY WHICH SHOULD HAVE THE OTHER VALUES MIXED IN (price, des, title) --></td>
      <td><?php echo $row['saleid']; ?></td>
      <td><?php echo $row['des']; ?></td>
      <td><?php echo $row['title']; ?></td>
      <td><?php echo $row['price']; ?></td>
    <?php
     if($row['status']=='Listed')
      echo "<td><span class='label label-success'>".$row['status']."</span></td>"; 
     else if($row['status']=='Awaiting')
      echo "<td><span class='label label-warning'>".$row['status']."</span></td>";
    ?>
      <td><a href="?view=<?php echo $row['id']; ?>" role="button" class="btn btn-success btn-xs" ><i class="fa fa-eye"></i></a> <a href="?edit=<?php echo $row['id']; ?>" role="button" class="btn btn-primary btn-xs" onclick="return confirm('Want to edit?'); " ><i class="fa fa-edit"></i></a> <a href="?del=<?php echo $row['id']; ?>" role="button" class="btn btn-danger btn-xs" onclick="return confirm('Confirm Delete!'); " ><i class="fa fa-trash"></i></a></td>
    </tr>
     <?php
      }
     ?>

   </tbody>
</table>

1 个答案:

答案 0 :(得分:0)

示例:

模型

public function select_data($id) {  
  $this->db->select(*); //or any fields
  $this->db->where('id', $id);
  $query = $this->db->get('table_name');
  return $query->row_array();               
}

控制器:

$data = $this->your_model_name->select_data($id); /id of the specified person
//pass data to the view
$this->load->view('your_view_file', $data);

查看:

//display name or description where 'desc' is your filed name from DB
<? echo $data['desc'] ?>

或将其与静态数据混合使用:

<p>
    My name is <? echo $data['name'] ?>.
</p>
<p>
    Description of the person: <? echo $data['desc'] ?>
</p>