Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by thenorman138

  1. I have a successful select query, where I'm looping and building a row for getting parameters which works correctly while ($row = $orderDetailCheck->fetch(PDO::FETCH_ASSOC)) { $params = [ ":INVOICE_NUMBER" => $row["INVOICE_NUMBER"], ":CUSTNM" => $row["CUSTNM"], ":SELLINGN" => $row["SELLINGN"], ":GROUP" => $row["GROUP"], ":DTL12" => $row["DTL12"], ":DTL13" => $row["DTL13"], ":QUANTITY" => $row["QUANTITY"], ":COUNT_PLMN_1" => $row["COUNT_PLMN_1"], ":LAST_DATE" => $row["LAST_DATE"], ]; } My issue now is that, for each row, I need to perform two merges because the data from that select is going to be split into two tables in db2. Some values are truly split between the tables but some values are shared between the two. I'm not sure the best way to perform these two merges because if the first one (products table) inserts, then it creates an ID that I need as a foreign key basically, to insert into the orders table. So on insert I need to grab that newly created ID and use it for ```product_id``` in the second merge. If the first merge performs the update when matched, then I need to grab the existing ID for that record so that I can update the proper record in the orders table. My two merge statements: /*products table*/ MERGE INTO products AS P USING(VALUES( :GROUP, :DTL12, :DTL13, :CUSTNM, :SELLINGN, :COUNT_PLMN_1, :LAST_DATE ) ) AS S(GROUP,DTL12,DTL13,CUSTNM,SELLINGN,COUNT_PLMN_1,LAST_DATE) ON s.GROUP = p.GROUP and s.DTL12 = p.DTL12 and s.DTL13 = p.DTL13 and s.CUSTNM = p.CUSTNM WHEN MATCHED THEN UPDATE SET LAST_DATE = s.LAST_DATE WHEN NOT MATCHED THEN INSERT VALUES (s.GROUP,s.DTL12,s.DTL13,s.CUSTNM,s.SELLINGN,s.COUNT_PLMN_1,s.LAST_DATE) /*ORDERS Table*/ MERGE INTO ORDERS AS PO USING(VALUES( /*need foreign key, which is id from products table*/ :QUANTITY, :LAST_DATE, :INVOICE_NUMBER )) AS S(PRODUCT_ID,quantity_ordered,LAST_DATE,invoice_number) ON s.PRODUCT_ID = po.id WHEN MATCHED THEN UPDATE SET LAST_DATE = s.LAST_DATE, quantity_ordered = s.quantity_ordered, invoice_number = s.invoice_number WHEN NOT MATCHED THEN INSERT VALUES (s.PRODUCT_ID, s.quantity_ordered, s.LAST_DATE, s.invoice_number) Examples: If my ROW Returns INVOICE | CUSTNM | SELLINGNUM | GROUP | DTL12 | DTL13 | QUANTITY | COUNT_PLMN_1 | LAST_DATE ================================================================================================================== 1122 123 321 995 1452 12 13 5 '2018-12-14' Then my insert into products would be products ID | GROUP | DTL12 | DTL13 | CUSTNM | SELLINGNUM | COUNT_PLMN_1 | LAST_DATE ========================================================================================================== 1 995 1452 12 123 321 5 '2018-12-14' and my insert to orders: ORDERS PRODUCT_ID | QUANTITY_ORDERED | LAST_DATE | INVOICE ============================================================ 1 13 '2018-12-14' 1122 But if my next record matched on my unique qualities with a new invoice, quantity and date ROW Returns INVOICE | CUSTNM | SELLINGNUM | GROUP | DTL12 | DTL13 | QUANTITY | COUNT_PLMN_1 | LAST_DATE ================================================================================================================== 1133 123 321 995 1452 12 4 5 '2018-12-18' Then I would update products like so: products ID | GROUP | DTL12 | DTL13 | CUSTNM | SELLINGNUM | COUNT_PLMN_1 | LAST_DATE ========================================================================================================== 1 995 1452 12 123 321 5 '2018-12-18' and update orders like so: ORDERS PRODUCT_ID | QUANTITY_ORDERED | LAST_DATE | INVOICE ============================================================ 1 4 '2018-12-18' 1133 I guess the main question is: How can I get the ID of a record from the products table (whether it's an existing match OR newly created in the merge) and once I get it, how can I use it for the 2nd merge?
  2. Ah I see what you mean. So there's no way to create sub headers for laravel excel?
  3. I currently have an array that I've built that dumps like this: 0 => array:11 [▼ "category_code" => "123" "category_name" => "Testing" "category_description" => "This is a test category" 19738 => array:5 [▼ "identifier" => "720368842943" "description" => Test Description One "count" => 4 "details" => array:2 [▼ 0 => array:3 [▼ "detail_code" => "2751" "detail_code2" => "43" "detail_specifier" => "Detail One" ] 1 => array:3 [▼ "detail_code" => "2681" "detail_code2" => "9" "detail_specifier" => "Detail Two" ] ] "prices" => array:1 [▼ "01" => "1129.00" ] ] 19739 => array:5 [▼ "identifier" => "720368844121" "description" => "Test Description Two" "count" => 4 "details" => array:2 [▼ 0 => array:3 [▼ "detail_code" => "2751" "detail_code2" => "43" "detail_specifier" => "Detail One" ] 1 => array:3 [▼ "detail_code" => "2681" "detail_code2" => "9" "detail_specifier" => "Detail Two" ] ] "prices" => array:1 [▼ "01" => "1490.00" ] ] I'm using laravel excel in order to export that as an excel file, but it's not quite working the way I intend When it exports to excel I only get the top level info: 123 | Testing | This is a test category But I want to get that info as a header and then each subsequent product for that category as a row, so with the example above it would look like: 123 | Testing | This is a test category ==================================================================================================================== 19738 | 720368842943 | Test Description One | 4 | 2751 | 43 | Detail One | 2681 | 9 | Detail Two | 1129.00 19739 | 720368844121 | Test Description Two | 4 | 2751 | 43 | Detail One | 2681 | 9 | Detail Two | 1490.00 Here's the excel code with the array I'm using, which is dumped above: $allCategoryResult= array(); foreach($prices->categories as $category){ $categoryItem = array(); $categoryItem["category_code"] = $category->category_code; $categoryItem["category_name"] = $category->category_name; $categoryItem["category_desc"] = $category->category_desc; foreach($category->skus as $sku){ $skuItem = array(); $skuItem["identifier"] = $sku->sku_info->identifier; $skuItem["description"] = $sku->sku_info->item->description; $skuItem["count"] = $sku->sku_info->item->item_type->count; $skuItem["details"] = array(); foreach ($sku->sku_info->details as $details) { $detailsItem = array(); $detailsItem["detail_code"] = $details->detail_code; $detailsItem["detail_code2"] = $details->detail_code2; $detailsItem["detail_specifier"] = $details->detail_specifier; $skuItem["details"][] = $detailsItem; } $skuItem["prices"] = get_object_vars($sku->prices); $itemCode = $sku->sku_info->item->item_code; $categoryItem[$itemCode] = $skuItem; } $allCategoryResult[] = $categoryItem; } $name = 'Test Export'; $build = Excel::create($name, function ($excel) use ($allCategoryResult) { $excel->setTitle('Test Export'); $excel->sheet('Test Export', function ($sheet) use ($allCategoryResult) { $sheet->fromArray($allCategoryResult);
  4. I'm currently looping on an array with this structure: Categories{ CategoryName CategoryCode CategoryDescription Products{ product_info{ product_code product_type{ CountNumber ProductDescription } } prices{ "wholesale":"250", "retail":"400" } } } I'm looping on the above array at each level, and I've declared an array so that I can put all my needed values into it $priceResult = array(); foreach($prices->categories as $category){ $categoryName = $category->category_name; $categoryCode = $category->category_code; $categoryDescription = $category->category_desc; foreach($category->products as $product){ foreach($product->product_info as $info){ $product_code = $info->product_code; foreach($info->product_type as $type){ $CountNumber = $type->CountNumber; $ProductDescription = $type->ProductDescription; } } foreach ($product->prices as $price => $amount) { $price_amount = $amount; } } } The problem I'm having is I don't know how to properly push into that new ```$priceResult``` array so that I can use PHPExcel to put it into a format with a subheader. The format I would want from the above example would be something like this Test Category 1 | 123 | Category for Testing ================================================== PRD123 | 12 | Product for Testing | 150.00 PRD112 | 17 | Product for Testing | 250.00 Test Category 2 | 321 | New Category for Testing ===================================================== PRD189 | 16 | Product for Testing | 450.00 PRD139 | 34 | Product for Testing | 350.00 So basically I want to call PHPExcel on my $priceResult array in order to get that format where I can list my category info, and for each product within that category, I'd have a product row. Everything would be grouped by the category main header $build = Excel::create($name, function ($excel) use ($priceResult) { $excel->setTitle('Test Products'); UPDATE: SO I'm thinking my desired resulting array would be something like: CategoryCode : 123 CategoryName : TestCategory CategoryDescription: For Testing Products{ 0{ Product_code : 123, CountNumber : 12, ProductDescription: Test Product, price_amount : 150.00 }, 1{ Product_code : 112, CountNumber : 32, ProductDescription: Test Product 2, price_amount : 250.00 } } That way each category can be a header and all of its products can be rows for each category
  5. I have a php script that I've been running that seems to have been working but now I'm wondering if some of my logic is potentially off. I select records from a db table within a date range which I put into an array called ```$validCount``` If that array is not empty, that means I have valid records to update with my values, and if it's empty I just insert. The trick with the insert is that if the ```STORES``` is less than the ```Quantity``` then it only inserts as many as the ```STORES``` otherwise it inserts as many as ```Quantity```. So if a record being inserted with had Stores: 14 Quantity:12 Then it would only insert 12 records but if it had Stores:1 Quantity:20 It would only insert 1 record. In short, for each customer I should only ever have as many valid records (within a valid date range) as they have stores. If they have 20 stores, I can have 1 or 2 records but should never have 30. It seems like updating works fine but I'm not sure if it's updating the proper records, though it seems like in some instances it's just inserting too many and not accounting for past updated records. This is the logic I have been working with: if(!empty($validCount)){ for($i=0; $i<$row2['QUANTITY']; $i++){ try{ $updateRslt = $update->execute($updateParams); }catch(PDOException $ex){ $out[] = $failedUpdate; } } }else{ if($row2["QUANTITY"] >= $row2["STORES"]){ for($i=0; $i<$row2["STORES"]; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $out[] = $failedInsertStore; } } }elseif($row2["QUANTITY"] < $row2["STORES"]){ for($i=0; $i<$row2["QUANTITY"]; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $out[] = $failedInsertQuantity; } } } } Let's say customer 123 bought 4 of product A and they have 10 locations customerNumber | product | category | startDate | expireDate | stores ---------------------------------------------------------------------------------- 123 1 A 2018-08-01 2019-03-01 10 123 1 A 2018-08-01 2019-03-01 10 123 1 A 2018-08-01 2019-03-01 10 123 1 A 2018-08-01 2019-03-01 10 Because they purchased less than their store count, I insert 4 records. Now if my ```$validCheck``` query selects all 4 of those records (since they fall in a valid date range) and my loop sees that the array isn't empty, it knows it needs to update those or insert. Let's say they bought 15 this time. Then I would need to insert 6 records, and then update the expiration date of the other 9 records. customerNumber | product | category | startDate | expireDate | stores ---------------------------------------------------------------------------------- 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 123 1 A 2018-08-01 2019-03-11 10 There can only ever be a maximum of 10 (store count) records for that customer and product within the valid date range. As soon as the row count for that customer/product reaches the equivalent of stores, it needs to now go through and update equal to the quantity so now I'm running this but it's not running and no errors, but it just returns back to the command line $total = $row2['QUANTITY'] + $validCheck; if ($total < $row2['STORES']) { $insert_count = $row2['QUANTITY']; $update_count = 0; } else { $insert_count = $row2['STORES'] - $validCheck; // insert enough to fill all stores $update_count = ($total - $insert_count); // update remainder } for($i=0; $i<$row2['QUANTITY']; $i++){ try{ $updateRslt = $update->execute($updateParams); }catch(PDOException $ex){ $failedUpdate = "UPDATE_FAILED"; print_r($failedUpdate); $out[] = $failedUpdate; } } for($i=0; $i<$insert_count; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $failedInsertStore = "INSERT_STORE_FAILED!!!: " . $ex->getMessage(); print_r($failedInsertStore); $out[] = $failedInsertStore; } }```
  6. @ginerjm thank you, you're right. I'm dumping each variable and they return NULL
  7. @requinix thank you for your answer. I've tried this using this for my php: $pageID = $_POST['currentPageID']; $newTime = $_POST['datePicker']; $newEndTime = DateTime::createFromFormat('m/d/Y h:i A', $newTime); $convertedDateTime = $newEndTime->format('Y-m-d H:i:s'); $extendExpiration = " UPDATE pages SET end_time = '$convertedDateTime' WHERE id = '$pageID'; "; But I'm still getting an error in my developer network console: "Undefined index: currentPageID Undefined index: datePicker Call to a memeber function format() on boolean"
  8. I only put that in for another testing function, but upon success I'm removing it
  9. I'm having an issue related to creating forms within a foreach loop. As of now, I have 3 forms in a div, each with their own datepicker instance and submit button ( also using a hidden input for the pageID) The datepickers are unique and working independently, but when it comes to posting the data via ajax and handling it in a php script, It's not inserting data into my db because the names of my two inputs are not unique. I don't really know how to make them unique on the form and then handle those unique names back in the script. Only one form will be submitted at a time so I'm trying to make it to where the user can click on any of these datepickers, select a date and submit, and the ajax will handle only the page ID and the datepicker value for that form submitted and the PHP script will then insert. The sql in my php script works but my POST variables are where I'm having the issue here. Any help is much appreciated. <?php foreach($expiredPages as $expiredPage): ?> <form id="updateTime_<?php echo $expiredPage['id']?>" class="updateTime" method="POST"> <input type="hidden" name="currentPageID<?php echo $expiredPage['id']?>" value="<?php echo $expiredPage['id']?>"> <div class="datepick input-group date" id="datetimepicker_<?php echo $expiredPage['id']?>" data-target-input="nearest"> <input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker_<?php echo $expiredPage['id']?>" name="datePicker<?php echo $expiredPage['id']?>" /> <span class="input-group-addon" data-target="#datetimepicker_<?php echo $expiredPage['id']?>" data-toggle="datetimepicker"> <span class="fa fa-calendar"></span> </span> </div> <input type="submit" name="Extend Date" class="extendDate"> </form> <?php endforeach; ?> <script type="text/javascript"> $(".extendDate").click(function(){ event.preventDefault(); var string = $('.updateTime').serialize(); console.log(string); // AJAX Code To Submit Form. $.ajax({ type: "POST", url: "extendTime.php", data: string, dataType: 'json', cache: false, success: function(response){ location.reload(); } }); }); </script> extendTime.php $pageID = $_POST['currentPageID']; $newTime = $_POST[$dtPick]; $newEndTime = DateTime::createFromFormat('m/d/Y h:i A', $newTime); $convertedDateTime = $newEndTime->format('Y-m-d H:i:s'); $extendExpiration = " UPDATE pages SET end_time = '$convertedDateTime' WHERE id = '$pageID'; "; if($mysqlConn->query($extendExpiration)=== TRUE){ echo "SUCCESS"; }else{ echo "Could not extend Time"; }
  10. @requinix I feel like I'm on the right track logically maybe? My problem is, if at any time I have 3 or 4 different sized divs with their own textarea/tinymce editor, how can I fairly simply arrange this to save the content of each with a corresponding value from each (1,2,3,etc.) to identify the panel type, all while still only inserting one page record?
  11. Can you give an example of the 2nd option? Again, this works for me as far as inserting 1, but I really just need help to use multiple instances of tinymce editors and potentially looping my insert for content and panels. I'm so beyond stuck here
  12. I have a CMS that I've built allowing users to create a 'Page' made up of different panels each with their own content. I've made this work so that a user can create a page with one panel and one textarea of content but I still can't figure out how to do this for multiple panels/content. Currently, if the page load gets the value of '1' from the URL value, it loads html templates with a fullwidth div and halfwidth div. I'm trying to set the panel type of each with hidden input types and they each have their own tinymce text area. <?php if($value == 1){?> <form method="post"> <div class="col-lg-12 fullWidth" id="full"> <input type="hidden" name="fullWidth" value=""> <div class="fullContent" style="background-color: white; height: 100%;"> <form id="form-data3" method="post"> <textarea class="original" id="mytextarea3" name="fullText">Some Text Here</textarea> <input type="submit" value="Save Content"> </form> </div> </div> <div class="col-lg-12 halfWidth" id="half"> <input type="hidden" name="halfWidth" value=""> <div class="halfContent" style="background-color: white; height: 100%;"> <form id="form-data4" method="post"> <textarea class="original" id="mytextarea4" name="halfText">Some Text There</textarea> <input type="submit" value="Save Content"> </form> </div> </div> </form> <?php } ?> Once this is done and they go to save page, there is another form that lets them set the title of the page and it also gets the page type ($value from above) <form action="addPage.php" method="post"> <input type="hidden" name="pageType" value="<?php echo $value;?>">//This comes from the url value <input class="form-control" id="addTitle" name="addTitle"> <input type="submit" name="Save Page"> The problem is, when I now call my addPage.php script to insert the records, I don't know how to pass the values correctly so that I add one page record (the $value for page_type_id and the Title) but then insert 2 content and panel records for the text areas. Here's my expected insert in the case of the above code: pages ID | Title | page_type_id 1 | TitleNew | 1 /*this comes from $value*/ content ID | Content 1 | Some Text Here 2 | Some Text There panels ID | panel_type_ID | page_id | content_id 1 | 1 | 1 | 1 2 | 2 | 1 | 2 This works for one insert in all 3 tables but if I can set multiple panel types to each div, how can I modify this to still insert the one page record but successfully account for multiple panel and content? Here's the add page script //Insert Page $title = $_POST['addTitle']; $page_type = $_POST['pageType']; $addpage = " INSERT INTO pages (title, page_type_id) VALUES ('$title','$page_type'); "; $mysqlConn->query($addpage) $page_id = $mysqlConn->insert_id; //Insert Content $content = $_POST['page_content']; $addContent = " INSERT INTO content(content) VALUES('$content'); "; $mysqlConn->query($addContent); $cont_id = $mysqlConn->insert_id; //Insert panel(s) $panelID = $_POST['panelType']; $addPanel = " INSERT INTO panels(panel_type_id, page_id, cont_id) VALUES ('$panelID', '$page_id', '$cont_id'); "; $mysqlConn->query($addPanel);
  13. @requinix this is a further developed example of a question you helped me with the other day. Could you help me understand how I would serialize here? Basically submitting multiple records for each panel type but only one record for page type
  14. @dalecosp this is the question I was referencing, it uses a lot of the principals from the last question but I'm trying to set input types for the different divs and then loop if possible
  15. I actually created a new post a few hours ago that more specifically covers my problem if you care to take a look @dalecosp, I was able to get the insert working for one panel but trying to get it fixed for multiple panels and Content
  16. @dalecosp can I use php to loop hidden inputs? So if I have multiple instances of the page type that is being loaded there?
  17. Overview: I've made a CMS that has the intent of the user creating one page, which is comprised of multiple assigned panels, each of which has it's own assinged content. I have a simple full width page template that has two divs corresponding to panels, with the respective IDs 'background' and 'full' fullWidth.php <div class="row middle" id="background"> <div class="col-lg-12 fullWidth" id="full"> <div class="fullContent" style="background-color: white; height: 100%;"> </div> </div> </div> My templates.php file gets the URL value from the link that called it and loads the template based on the value. In this case the value is 1 so it loads fullwidth.php. What I'm trying to do though is take the div IDs from fullwidth.php and assign them to PHP variables based on the ID. So in the below example, div ID full would have $panelType of 1 and div ID background would have $panelType of 8. Without my below pseudo code block, if I just set $panelType = 1 and submit the form calling addPage.php, everything works fine but it only works for the one panel type. However, with this example below I want to set multiple panel types which would correspond with multiple instances of the hidden inputs. I'm trying to solve two issues: 1.) Assiging multiple panelType instances according to DIV ID, which includes looping multiple hidden inputs, and 2.) making sure that addPage.php inserts correctly meaning inserting one page record, getting that page ID, then inserting multiple content records (getting each ID) and inserting multiple panel records (using the one page ID and the multiple corresponding content IDs) Again, If I just assign $panelType = 1 and do this whole process, it succesfully creates the page record, content record and panel record. But I need to alter this for multiple $panelType variables as well as set those $panelType variables accordingly Templates.php <?php $value = isset($_GET['value']) ? $_GET['value'] : 1;?> <?php if($value == 1){ include 'class/fullWidth.php' /*$panelType = 1*///I've been using this to test and it successfully inserts one page record, one content record, and one panel record /*pseudo code for what I'm trying to attempt, not currently using this*/ $panel = $html->find('div[id]'); if ($panel == 'full') { $panelType = 1; }elseif ($panel == 'background') { $panelType = 8; } } ?> <form action="addPage.php" method="post"> <input type="hidden" name="pageType" value="<?php echo $value;?>"> <!--This will always be one value, the URL value that I GET up top--> <input type="hidden" name="panelType" value="<?php echo $panelType;?>"> <!--This, I've been testing with one $panelType but now it needs to be multiple. In this example, I would be expecting $panelType of 1 and 8--> <input type="hidden" id="new" name="page_content" value=""><!--I'm using javascript to set this to page content from TInyMCE, there will be multiple of these--> <input class="form-control" id="addTitle" name="addTitle"> <input class="form-control" id="durationSet" name="durationSet"> <input type="submit" name="Save Page"> </form> addPage.php /***CREATING ONE PAGE INSERT***/ $page_type = $_POST['pageType']; $title = $_POST['addTitle']; $duration = $_POST['durationSet']; $addpage = " INSERT INTO pages (title, page_type_id, display_id, duration) VALUES ('$title','$page_type','$display_id','$duration'); "; if ($mysqlConn->query($addpage) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addpage . "<br>" . $mysqlConn->error; } $page_id = $mysqlConn->insert_id; //Get this page ID for panel inserts /***CREATING MULTIPLE CONTENT INSERTS***/ $content = $_POST['page_content']; //Should have multiple of these $addContent = " INSERT INTO content(content) VALUES('$content'); "; if ($mysqlConn->query($addContent) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addContent . "<br>" . $mysqlConn->error; } $cont_id = $mysqlConn->insert_id; //Get these content IDs for panel inserts /***CREATING MULTIPLE PANEL INSERTS***/ $panelID = $_POST['panelType']; $addPanel = " INSERT INTO panels(panel_type_id, page_id, cont_id) VALUES ('$panelID', '$page_id', '$cont_id'); "; if ($mysqlConn->query($addPanel) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addPanel . "<br>" . $mysqlConn->error; }
  18. Wow, that's a lot of insight thank you! So, I could feasibly wrap the $value in a hidden form as well as the panel type Id from fullwidth.php rather than using a div ID. That sounds better to me, if I'm understanding you right
  19. Ok so, for mysqli $newID would be the variable and it will automatically get the id for each one? I was thinking of running an insert for the page record, an insert for content, and then the panel last since it has to have those IDs, so would I have to set a $newID for each of the first 2 Inserts? (sorry, I'm usually mostly front end and I'm so stuck on this)
  20. short(est) version: I created a simple CMS that allows the user to choose from 4 templates. Each template has different panel types. For this example I'm showing a full page template which only has one full page panel. Basically, the panel offers up an instance of TinyMCE to allow the user to create text/image content for the panel. The flow is: Content ->(assigned to)->Panel->(assigned to)->Page->(assigned to)->display So in this case, the user selects a link which passes a value through the URL, in this case the value is 1. This tells templates.php to include fullWidth.php So templates.php has a save form with a submit button, and the loaded fullWidth.php file has the panel template which gives us the number for panel type as well as the content in a textarea. My problem is, I need to fully realize a function that saves a page (which by proxy saves records for content and panels as well) So with the code below, I would be inserting into 3 different tables basically, but the ```panels``` table is inserting foreign keys; the IDs of the newly created ```pages``` entry as well as the newly inserted ```content``` entry. I know the majority of this is just inserting some form values into the database but I have 2 main hurdles here: 1. How to insert values that aren't in the form such as the content and panel_type ID from fullwidth.php as well as the passed in $value in templates.php 2. How to create a function that does the main inserting with the ability to grab 2 different IDs used as foreign keys for panels. For this example with the code I'm posting (assuming the user is selecting the hard coded ```<options>``` I'm using below), I would insert: saveContentPage.php //This is complete pseudo code, I'm not sure how the syntax would change for the different types $title= $_POST['$title']; $pageType= $_POST['$value']; $displayId = $_POST['#areaSelect']; $start_time = now(); $end_time = $_POST['#datePicker']; $slide_order = $_POST['#orderSet']; $duration = $_POST['#durationSet']; $sql="INSERT INTO pages(title, page_type_id, display_id, start_time, end_time, slide_order, duration) VALUES ('$title','$pageType','$displayId','$start_time','$end_time','$slide_order','$duration')"; //Here I need to pass the content from the included fullwidth.php to get the textarea content and the panel_type_id $content = $_POST['textArea'] $sql = "INSERT INTO content(content) Values('$content')"; if(#id = FullPage){ $panel_type = 1; } $sql = INSERT INTO panels (panel_type_id, page_id, cont_id) VALUES ('$panel_type', /*ID that was created from 'pages' insert*/, /*ID that was created from 'content' INSERT*/) How can I create a function that performs the necessary insert(s)? Code: templates.php <!-- check GET 'value' --> <?php $value = isset($_GET['value']) ? $_GET['value'] : 1;?> <!-- If value is 1 then load the full page template class --> <?php if($value == 1){?> <?php include 'class/fullWidth.php'?> <!-- Submit button that links to modal with a 'save page' form inside --> <div class="modal fade" id="savePageModal" tabindex="-1" role="dialog" aria-labelledby="savePageLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="savePageLabel">Page Details:</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <div class="form-group"> <!-- this is the URL value i.e. templates.php?value=1 and should insert into pages.page_type_id --> <label>Page Type: <?php echo $value;?></label> </br> <!-- This is page title, should map to pages.title --> <label for="addTitle">Page Title:</label> <input class="form-control" id="addTitle"> </input> <!-- This shows the displays, will save the ID of the selected option to pages.display_id --> <label for="areaSelect">Select An Area</label> <select class="form-control" id="areaSelect"> <option>4</option> </select> <!-- Input for seconds, will save to pages.duration --> <label for="durationSet">Set A Duration (in seconds)</label> <input class="form-control" id="durationSet"> </input> <!-- User selects order of slide --> <label for="orderSet">Set Slide Order</label> <select class="form-control" id="orderSet"> <option>3</option> </select> <!-- This datepicker allows user to pick a date and time, will save as TIMESTAMP to pages.end_time --> <label for="expirationSelect">Set Expiration Date/Time</label> <div class="form-group"> <div class="datepick input-group date" id="datetimepicker" data-target-input="nearest"> <input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker"/> <span class="input-group-addon" data-target="#datetimepicker" data-toggle="datetimepicker"> <span class="fa fa-calendar"></span> </span> </div> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> </div> fullwidth.php <!-- This file is loaded based on page type ($value) from templates.php It loads an HTML template which has a main div houseing the panel_type and it has a textarea that houses the content --> <div class="row middle"> <div class="col-lg-12 fullWidth"> <!-- This Div ID is 1 which maps to the panel_type of this div, so upon saving It should insert to panels.panel_type_id a value of 1 --> <div class="fullContent" id="fullPage" style="background-color: white; height: 100%;"> <!-- THis is simply a modal that givees the user an interface to use TinyMCE in order to fill the content of mytextarea3 --> <div class="modal fade bd-example-modal-lg" id="fullModal" tabindex="-1" role="dialog" aria-labelledby="fullLabel" aria-hidden="true"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="fullModal">Content Library:</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <h3>Create your own content</h3> <form id="form-data3" method="post"> <!-- This is the text area that should be saved to content.content --> <textarea id="mytextarea3"></textarea> <input type="submit" value="Get Data"> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button> </div> </div> </div> </div> </div> </div> </div>
  21. Oh thank you, that's a big help! I'm treating this similar to WordPress inserting content into certain divs of a theme basically. So every display will call a display.php page with the relative content from the database, if that makes sense
  22. I'm creating a very lightweight interface that allows some users in our office to select predefined content (text, images, youtube/social links) or create their own text content using TinyMCE, and allow it to be viewed on different displays throughout the building. In concept it's fairly simple: The user chooses one of four templates that each have a banner and footer, and either 1,2 or 3 div elements inside the body for different content. Each of these is defined as a panel. The template links pull 1 of 4 php class files that houses the html templating for each page and then I'm assinging tags to each panel type. So I have panel types of Banner, Footer, FullWidth, HalfLeft, HalfRight, etc. So if a user chooses the full width template, it has a banner, a footer, and one full width container div (ID is fullWidth). Upon saving this, that means I'm saving three panels to the database (panel_type of banner, footer, or fullWidth) as well a page record, since the three panels make up one page that will be assigned to a display or displays. Would it make the most sense here to have a class for saving/adding panels and a separate class for saving/adding pages? In other words, when the save button is clicked, I'm at one time saving 3 panels that relate by foreign key to 1 page. At the same time this saves a reference to one or multiple displays. I'm basically asking, would I be better off to have one big class that saves all of this to the three respective tables, or should I call multiple classes, one for each part. Here's an example of a full width template: <div class="row top"> <div class="col-lg-12"> <div class="row" id="banner"> Banner Text </div> </div> </div> <div class="row middle"> <div class="col-lg-12"> <div id="fullWidth" > <textarea id="mytextarea"></textarea><!--This is the usage of TinyMCE for their text content--> <input type="submit" value="Save Data"> </div> </div> </div> <div class="row bottom"> <div class="col-lg-12"> <div class="marquee" id="footer">Footer Text</div> </div> </div> So they chose a template which calls a php file containing that above code (the html templating) and now upon submit I would call a 'save' class that saves the page record and assigns the 3 panels with a foreign key to the page ID. Does this sound like a decent approach to this?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.