私は、この(私はMySQLのテーブルからすべてのデータをフェッチし、ページに表示するためにCodeIgniterの中でMVCを使用していますCodeIgniterの更新特定の値
をpost_like、post_idのを持っているMySQLデータベース、post_number内のテーブルを持っています一部)
行われ、私はpost_idのに対応してMySQLのテーブルにpost_likeに+1を追加し、各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);
}
?>
ドンしてください
function data_addition($post_id){
$post_like = $this->db->get_where('post_tbl', array('post_id' => $post_id))->row();
//trying to add 1 the post_like and update it in the db
$add_one_to_data = (int) $post_like->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);
}
あなたの助けに感謝します。私は2番目の$ add_one_to_data +1が配列内にある必要がないことを認識しました。すでに上で行っています。 – mark