One of the needs of the e-commerce project on hand today is : Automatically distribute the coupons in the order to the buyer , So just update a few rows of data in the coupon table , Check the manual and network, there is no solution .

It's wrong to start with loops and traversals , because update Statement to update all the qualified lines , But it is not suitable to use subquery as a condition kiss(keep it simple, stupid.) The specification of .

So try to put set Statement addition ar, It's done .

public function status($order_id, $slug)
{
if($slug==='2')
{
# Delivery process , Let's see if it's a coupon first
if($this->_is_coupon_order($order_id))
{
$this->load->model('m_cart', 'cart', true);
$undiscounted = $this->cart->items($order_id);
$discounted = $this->cart->items($order_id, true);
$merged = array_merge($undiscounted, $discounted);
$this->db->where('status', 0)
->where('rule_id', $merged[0]->type_id)
->limit($merged[0]->item_quantity)
->set('user_id', $merged[0]->user_id)
->update('coupon');
}
$this->db->where('id', $order_id)->set('status', 2);
}
$this->db->update('order');
return $this->db->affected_rows();
}

Codeigniter stay Active Record Limit the number of batch updates in

  1. mysql Copy the values of multiple field names to another field name ( Batch update data ) String splicing cancat Practical examples

    mysql Copy the values of multiple field names to another field name ( Batch update data )mysql String splicing cancat Practical examples : mysql update set Add multiple fields , If it's a number addition, you can use + Number ( notes :hund ...

  2. Mybatis Batch update in (updateBatch)

    Update multiple data , Every piece of data is different Background description : Usually, if you need to update more than one piece of data at a time, there are two ways ,(1) Loop through the business code and update one by one .(2) Update all data at once ( To be more precise, it's a sql Statement to update all data , One by one update operation ...

  3. jdbctemplate Batch update in use ,BigDecimal The connection and difference with modeling

    //jdbctemplate Batch new use MENU_ID_LIST It's the front-end page that passes to the back-end control layer , And then from the control layer to the implementation layer List //JdbcTemplate yes spring jdbctemplate By noting ...

  4. From the perspective of source code React JS Medium batch update State The strategy of ( Next )

    In this article, we continue to learn from the source code perspective React JS Batch update in State The strategy of , For our further study and Research React for the purpose of . List of front articles In depth understanding of React JS Medium setState From source ...

  5. In architecture mode Active Record and Data Mapper

    In architecture mode Active Record and Data Mapper Concept In simple applications , Domain model is a simple structure consistent with database structure , There is a domain class for each database table , under these circumstances , It's necessary to make each object responsible for the database ...

  6. [ turn ]MySQL Batch update deadlock case analysis

    The article citations :http://blog.csdn.net/aesop_wubo/article/details/8286215 Problem description In the process of doing the project , Because of writing SQL Too casual , Accidentally threw a deadlock exception , ...

  7. DAL、DAO、ORM、Active Record Differentiation and analysis

    from :http://blog.csdn.net/suiye/article/details/7824943 Model Model The model is MVC The concept of , It refers to the operation of reading and changing data ( Business logic ). At first I was ...

  8. Statement and PreparedStatement Batch update

    advantage :1. Save delivery time . 2. Concurrent processing . PreparedStatement: 1) addBatch() Add a set of parameters to PreparedStatement Inside object . 2) executeBatch( ...

  9. mysql Batch update 、 Multi table update 、 Multi table delete

    In this article ,mysql Batch update in . Multi table update . Some instances of multi table deletion , Friends in need can refer to . The main content of this section : mysql Batch update . Multi table update . Multi table delete One , Batch update : Copy code example : update ...

Random recommendation

  1. Discuz The process of building the Forum

    1. System environment Operating system version :CentOS Linux  5.7 Kernel version :2.6.18-274.el5 arch:x86_64 apache edition :Apache/2.4.6 (Unix) mysql edition ...

  2. SMP and MAPP The difference between

    SMP(Symmetrical Multi-Processing), Symmetric multiprocessing systems , A collection of processors on a computer ( many CPU), various CPU Shared memory subsystem and bus structure . It is relative to asymmetric multiprocessing technology ...

  3. maven The second series maven Project creation and maven Project structure

    maven One of the series briefly introduces maven Basic information of , install and configure , Everyone to maven Have a general understanding of , But in maven Project development is far from enough , To learn more about maven, Now let's introduce maven Project creation and mave ...

  4. PowerDesigner Set line style ( A straight line , Broken line ...)

    PowerDesigner I can't flatter the drawing function in . 1. Modify the display settings Tools-->Display Preferences There are a lot of performance settings , What we need is Format Under menu . spot Modif ...

  5. CSS3 Introduction to properties in

    Concept : Shadow text grammar :text-shadow: length length length color Introduce : The first two parameters are the horizontal displacement distance and the vertical displacement distance of the shadow from the text . When using, the first two parameters must be specified , also ...

  6. [20171221] utilize rman Realization 2 Copy machine files .txt

    [20171221] utilize rman Realization 2 Copy machine files .txt --// Used yesterday rman duplicate establish dg, I see executing the following code : RMAN> duplicate target datab ...

  7. mysql Master slave configuration (5 Minutes to solve the problem )

    Conditions : An alicloud server (centos 6.6 +mysql 5.6) A Tencent cloud server (centos 7.2 +mysql 5.6) notes : Master and slave versions can be consistent or inconsistent , It needs to be explained , If both versions ...

  8. jsoup-1.7.2.jar package

    org.jsoup.Jsoup; org.jsoup.nodes.Document; org.jsoup.nodes.Element; org.jsoup.select.Elements;

  9. 《Effective C++》 The first 5 Chapter Realization - Reading notes

    Chapter reviews : <Effective C++> The first 1 Chapter Get used to C++- Reading notes <Effective C++> The first 2 Chapter structure / destructor / The assignment operation (1)- Reading notes <Effecti ...

  10. html Basics Forms

    One . Forms <form id="" name="" method="post/get" action=" The server responsible for processing &qu ...