multi insert update May 05, 2020, 10:34:44 AM Hello All,First I have made a copy of add page for table 'docs', then by editor I make my custom Form, that is working and all parameters are passed true POST method, // action="<?php print_link("docs/add?csrf_token=$csrf_token") ?>" but it insert only in one table 'docs', so I need to INSERT some VALUES in two more tables 'partner' , 'sales' and to UPDATE "qty" in 'product' what/where is the right way to do it?then I need to redirect to custom view page LAST record?So I'm confused from that in docsControler.php , function add(){ if($formdata){ $db = $this->GetModel(); $tablename = $this->tablename;....I could make my own functions and do it my way, but I would like to understand the logic here and do it right way!So advice how to make that multi-insert ? Quote Selected
Re: multi insert update Reply #1 – May 05, 2020, 04:28:07 PM @dobsun this video https://www.youtube.com/watch?v=UsLlG4EvkbQ describes the functions you are asking of and also look at this thread https://phprad.com/forum/index.php?topic=824.msg2705#msg2705, which shows a better way to do such update.Note: The best way for you to achieve what you want is to use page events. You can search the forum for more info on what you are trying to do. Quote Selected
Re: multi insert update Reply #2 – May 11, 2020, 09:40:24 AM @willvin thank you, page event it works for me!All works except SELECT array ?I have try many $params looking as$params = implode(',',array_keys($products_in_cart);print_r ($params) - return list of product id separated by comma as : 1024,1025,1026 $params = (array_keys($products_in_cart); print_r ($params) - return : Array ( [0] => 1024 [1] => 1025 [2] => 1026 )$arr = $db->rawQuery("SELECT * FROM product WHERE id = ?", $params);all that returns: error 500 Quote Selected Last Edit: May 11, 2020, 09:59:33 AM by dobsun
Re: multi insert update Reply #3 – May 11, 2020, 11:10:11 AM solved<?phpfor($i=0; $i<count($product_in_cart); $i++){$pid = $product_in_cart[$i];$params = array($pid);$arr = $db->rawQuery("SELECT * FROM product WHERE id = ?", $params);$product = $arr['0'];echo $product['name'];}?>I'm not sure it is right way, as we call server db multiple times in a loop , if you have better suggestions let me know Quote Selected Last Edit: May 11, 2020, 11:16:30 AM by dobsun
Re: multi insert update Reply #4 – May 13, 2020, 09:29:39 AM @dobsun you use this ? in your query when you know or can predict the num of array param you are passing to the query. So for each value in the array, you need to add the same number of this ? which is wrong in this situation.Use this instead:Code: [Select]$params = array($products_in_cart);$arr = $db->rawQuery("SELECT * FROM product WHERE id IN (?)", $params ); Quote Selected
Re: multi insert update Reply #5 – May 15, 2020, 10:30:59 AM Thank you very much!I have try that option many times, obviously with wrong syntax! Quote Selected