У нас вы можете посмотреть бесплатно How to Insert Data into Multiple Tables and Rows in CodeIgniter Efficiently или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Learn how to handle form submissions in CodeIgniter and insert data into multiple tables and rows seamlessly. `Simplify Your Database Operations` --- This video is based on the question https://stackoverflow.com/q/73982044/ asked by the user 'leanghy' ( https://stackoverflow.com/u/12684256/ ) and on the answer https://stackoverflow.com/a/73982343/ provided by the user 'Punit Gajjar' ( https://stackoverflow.com/u/5127330/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Insert multiple table and row in codeigniter Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Guide to Inserting Data into Multiple Tables and Rows in CodeIgniter When working on web applications using CodeIgniter, you may find yourself facing the challenge of inserting data into multiple tables simultaneously, especially when the data is being submitted through a single form. In this guide, we'll take a look at how to efficiently insert data into two tables: pms_service_fee and pms_service_fee_detail. Let's break down the problem and solution step by step. Understanding the Problem You have two tables in your database: pms_service_fee: This table contains general service fees information. pms_service_fee_detail: This table holds detailed entries for each service fee, linking them back to their parent entry in pms_service_fee. The goal is to take input from a form, process it, and insert appropriate data into both tables in one go. This kind of operation can save time and improve efficiency, so let's see how to do it. Proposed Solution To achieve this, we will utilize the db class in CodeIgniter for database operations. Let's break down the solution into clear sections: Step 1: Prepare the Data Before pushing data into the database, it's important to sanitize the input to prevent any SQL injection attacks or data corruption. The escape_array function is a common practice for this. [[See Video to Reveal this Text or Code Snippet]] Here, $data is the array containing all the inputs from your form. Step 2: Inserting Data into pms_service_fee Next, we need to insert the general service fee data into the pms_service_fee table. We can do this with an insert or update operation depending on whether we are editing an existing entry. [[See Video to Reveal this Text or Code Snippet]] Step 3: Collecting Details for pms_service_fee_detail Instead of hardcoding the entries for pms_service_fee_detail, we will use a loop to dynamically build the array of service fee details from user input: [[See Video to Reveal this Text or Code Snippet]] Step 4: Batch Insert into pms_service_fee_detail Finally, we need to insert the collected details into the pms_service_fee_detail table using the insert_batch method: [[See Video to Reveal this Text or Code Snippet]] Complete Code Example Here’s how it all fits together in the model function: [[See Video to Reveal this Text or Code Snippet]] Conclusion By following these steps, you can successfully insert multiple rows into different tables in CodeIgniter with minimal hassle. This method not only improves efficiency but also keeps your database operations clean and organized. Don’t hesitate to implement this in your next CodeIgniter project, and you’ll find dealing with complex forms a lot easier!