The code of the TP data layer for the increment and deletion check operation

Source: Internet
Author: User
This article brings the content is about the TP data layer to increase the deletion of the code, there is a certain reference value, there is a need for friends to refer to, I hope you have some help.

thinkphp data layer (model layer), add and revise to check the operation of super detailed explanation! Let's take a look below!

<?php namespace Home\model;use think\model;class Ymdmodel extends Model{public function __construct () {$this Dbyimudi = m (' Yimudi '); $this->dbyimudiuse = m (' Yimudi_use '); $this->dbyimudiinfo = m (' Yimudi_info '); $this Dbyimudici = M (' Yimudi_ci ');} Two tables associated query public function Getyimudione ($condition, $field) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->table (' yimudi_use yu,yimudi y ')->where (' yu.yimudi_id = y.yimudi_id '). $ Condition)->field ($field)->find ();}} Statistics a table satisfies the number of conditions public function Getyimudiusecount ($condition) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->where ($condition)->count ();}} Sum operation Public Function Getechangeyimudicount ($condition) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->table (' yimudi_use yu,yimudi y ')->where (' yu.yimudi_id = y.yimudi_id '). $ Condition)->sum (' Change_num ');}} (yimud_id Group) public Function getexchagebyyimudiid ($condition, $field) {if (! $condition) {return false;}else{return $this->dbyimudiuse->table (' yimudi_use yu,yimudi_ci yc ')->where (' yu.yimudi_id = yc.yimudi_id '). $condition)->field ($field)->group (' yu.yimudi_id ')->select ();}} Update operation public Function Updateyimudiuse ($condition, $data) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->where ($condition)->save ($data);} Multi-table connection query, paging gets data public function getyimudilist ($condition, $start, $size) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->table (' yimudi_use as Yu ')->join (' Yimudi as Y on yu.yimudi_id = y.yimudi_id ', ' Left ')->join (' Yimudi_cinema as YC in yu.yimudi_id = yc.cinema_id ', ' left ')->where ($condition)->field ($field )->limit ($start, $size)->select ();}} The data that is associated with two tables satisfies the public function Getyimudicount ($condition) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->table (' yimudi_use as Yu ')->join (' Yimudi as Y on yu.yimudi_id = y.yimudi_id ', "Left")->join (' Yimudi_ci as YC on yu.yimudi_id = Yc.yimudi_id ', ' left ')->where ($condition)->count ();}} Get Yimudi list--ajaxpublic function Getyimudilistajax ($condition, $start, $size) {if (! $condition) {return false;} Else{return $this->dbyimudiuse->table (' yimudi_use as Yu ')->join (' Yimudi as Y on yu.yimudi_id = y.yimudi_id ', ' Left ')->join (' Yimudi_ci as YC in yu.yimudi_id = yc.yimudi_id ', ' left ')->where ($condition)->field ($field)- >limit ($start, $size)->select ();}} Gets a single record public function getyimudicidecription ($condition, $file) {if (! $condition) {return false;} Else{return $this->dbyimudici->where ($condition)->field ($field)->find ();}} Paged Get list Public function getciyimudilist ($condition, $start, $size) {if (! $condition) {return false;} Else{return $this->dbyimudiciinfo->where ($condition)->limit ($start, $size)->select ();}} Multiple Table Association query one record public function Getciyimudibyid ($condition) {if (! $condition) {return false;}  Else{return $this->dbyimudiuse->table (' yimudi_use as Yu ')->join (' Yimudi as Y onyu.yimudi_id = y.yimudi_id ', ' left ')->join (' Yimudi_ci as YC in yu.yimudi_id = yc.yimudi_id ', ' left ')->where ($condi        tion)->field ($field)->find ();}} }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.