PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] PHP Codeigniter - Clone Data ( Works for only 1 single row , but not all row )

 January 28, 2022     codeigniter, codeigniter-3, php     No comments   

Issue

What i am trying to do:
Try to Clone Data (Update) from Table "Payment History" to "Payment" , But the problem right now is that in when i only select('Payment_Amount'), it works(update) but not everything , any idea ?

Payment Table

Payment_ID
Payment_Amount
Payment_Method
Payment_Remark

Payment History Table

Payment_ID
PaymentHistory_ID
Payment_Amount
Payment_Method
Payment_Remark

Both have the same column and same data type

My Code: Controller

public function updateHistory($Payment_ID){
        // with single Payment_ID

        //get data with specific column and ignore PaymentHistory_ID
        $query = $this->db->select('Payment_Amount','Payment_Method','Payment_Remark')->where('Payment_ID', $Payment_ID)->get('YOUR FROM TABLE');
        $result = $query->row_array();

        if($result)
        { // check if has data
            //then update to another table
            $this->db->where('Payment_ID', $Payment_ID)->update('YOUR TO TABLE', $result ); // To update existing record
        }
}

Based on the question that I have provided Codeigniter - Clone Data (But remove 1 column that is not exist ) , the codes works , but not the new problem that I am facing.

Note: New to CodeIgniter


Solution

 if(!empty($result)) { 
     $this->db->where('Payment_ID', $Payment_ID)->update('YOUR TO TABLE', $result[0]); // To update existing record
    }


Answered By - Tabrosh Shaikh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing