dongsuoxi1790 2012-09-08 12:23
浏览 31
已采纳

Codeigniter在使用activerecords检索时更新数据库中的列

I'am learning to make a blog in CodeIgniter 2.x . What I want - when user clicks on the link readmore on the blog's page, it will redirect him to the page with corresponding id to show him a full article.

Now, while retrieving a $query->row(); from a database in content_model.php, i want to update a viewed column in database at the same time. So instead of showing him for example 34 views, it will show 35 views, and when someone open the same link it will shows him by one more - 36 views.

What's the best way to do it without making it vulnerable to hackers somehow ?

Thank you in advance for any help.

  • 写回答

2条回答 默认 最新

  • douji9816 2012-09-08 13:10
    关注

    When you retrieving data from database using CI framework, you check this following:

        if ($result_from_get_function->num_rows()>0){
        return   $this->updateViewColoumnByOne();
        }else{
        return false;
        }
        function updateViewColoumnByOne(){
        //retrieve number of view in view column, suppose 12.
        //plus one with it; 12+1=13
       //update it.
       //again retrieve the new update number of views
       //and return.
       }
    

    I think this could help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?