<分区>
我在 MySql 数据库中有一个表,该表具有 post_id、post_number、post_like
我在 codeigniter 中使用 MVC 从 mysql 表中获取所有数据并将其显示在页面上(这部分已完成)
我需要为每个 post_id 添加一个按钮,将 +1 添加到 mysql 表中的 post_like,对应于 post_id。
因此,如果我点击 post_id 7 的 +1 按钮,post_like 应该只会增加 post_id 7。
这是我目前所拥有的!
view_page.php
<?php foreach($members as $value): ?>
<tr>
<td><?php echo $value['post_id']; ?></td>
<td><?php echo $value['post_like']; ?></td>
<td> <a href="plusone/<?php echo $value['post_id']; ?>">Add +1</a></td>
</tr>
<?php endforeach; ?>
controller_page.php
<?php
function plusone($post_id){
$this->load->model('model_page');
$this->model_page->data_addition($post_id);
redirect('controller_page/viewdata');
}
?>
Model_page.php
<?php
function data_addition($post_id){
//trying to add 1 the post_like and update it in the db
$add_one_to_data = $post_like+ 1;
$data = array(
'post_like' => $add_one_to_data +1
);
$this->db->where('post_id', $post_id);
$this->db->update('post_tbl', $data);
}
?>
请不要笑我在数组上面添加的$add_one_to_data,我不知道还能做什么
提前致谢