Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. As a rule, output to the page generally happens in the same order that it appears in your code. If you want the table after the form, output it after the form in your code. Not rocket science.
  2. <html> <body> <form> form stuff </form> <?php if (!empty($from) && !empty($to)) { ?> <table> table stuff </table> <?php } ?> </body> </html>
  3. make the output of the table conditional on there being input of dates (as you did with the processing).
  4. You are referencing $_GET['view'] but you do not have an input with that name ('view'). The name of your <select> is "sales_repid" so you need use $_GET['sales_repid']. Also, the "for" in you label for the select should be the id of the input element (should be for='rep' )
  5. Your call to fetchAll() puts the returned rows into $a_data. You need to loop through the array "$a_data" and output the content of each row.
  6. I don't see any code there that should output the results.
  7. Ticks are only used in SQL queries around identifiers. When using quotes (single or double) they should be in matching opening and closing pairs. do_check('<a href="\emwin\adm\cwfmob.txt' title="Coastal Water Forecast" target="_self">CWFMOB</a>','\emwin\adm\cwfmob.txt',60*60*60,'\emwin ...'); ^..............................^ ^......................^ ^.....^ ^.^ ^..........^ As you can see, you href does not have matching opening and closing quotes, throwinng other pairs out of synch. try do_check('<a href="\emwin\adm\cwfmob.txt" title="Coastal Water Forecast" target="_self">CWFMOB</a>','\emwin\adm\cwfmob.txt',60*60*60,'\emwin ...'); ^.....................^ ^......................^ ^.....^ ^........................................................................................^ ^.....................^ ^..........^ See https://www.php.net/manual/en/language.types.string.php
  8. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
  9. JQuery It makes life a lot easier when using javascript. <script type='text/javascript'> $(function() { $(".circ3").mouseover(function() { // handle mouseover event on elements with class "circ3" $(this).css("fill", "red") // $(this) is the target element - change its fill color $(this).css("fill-opacity", "1") // - change its opacity $("#grp1").removeClass('txt1').addClass('txt2') // change class of element with id = "grp1" }) $(".circ3").mouseout(function() { $(this).css("fill", "blue") $(this).css("fill-opacity", "0.3") $("#grp1").removeClass('txt2').addClass('txt1') }) }) </script>
  10. Your result binding is off. The first column in your SELECT clause is the employee name but you are binding that to sales_date when you bind the results. They need to be bound in the order they are selected. Put this line of code just before you create your database connection... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); DON'T use "*" in your select clauses, almost always specify the column names - it better documents what the query is doing. DO use code blocks (<> button) when posting code in the forums.
  11. Where did datatables suddenly appear? All your previous code has shown you generating the table in PHP
  12. As demonstrated, there is no reason why you should need to resort to javascript (all info is available on the server in PHP with no further client interaction required) You must be doing something wrong.
  13. Then place it somewhere else. The principle remains the same. Maybe <body> <h3><?=$table_title?></h3> <table class="table" id="myTable2"> <thead> <tr> <th>Rep</th> <th>Sales</th> <th>Cigars</th> <th>30%</th> <th>Rum/Souv.</th> <th>30%</th> <th>Comm.</th> </tr> </thead> </table> </body>
  14. You receive and reformat the dates in the PHP. So create the table title in PHP also. Why struggle to do it in the javascript on the client? Example <?php $from = $_GET['start'] ?? ''; $to = $_GET['to'] ?? ''; $comm_start = (new DateTime($from))->format('d/m/Y'); $comm_to = (new DateTime($to))->format('d/m/Y'); $table_title = "Commission: $comm_start &ndash; $comm_to"; ?> <body> <table class="table" id="myTable2"> <caption><?=$table_title?></caption> <thead> <tr> <th>Rep</th> <th>Sales</th> <th>Cigars</th> <th>30%</th> <th>Rum/Souv.</th> <th>30%</th> <th>Comm.</th> </tr> </thead> </table> </body>
  15. If you are reformatting the date in PHP, what are you trying to do with it in Javascript?
  16. I find date handling in javascript tedious work. Far easier in PHP or SQL if you can. PHP $date = '2023-04-30'; $formatted = (new DateTime($date))->format('d-m-Y'); echo $formatted; SQL mysql> SELECT date_format('2023-04-30', '%d-%m-%Y') as formatted; +------------+ | formatted | +------------+ | 30-04-2023 | +------------+
  17. I fixed the start/from issue in my last code Input HTML My revised code Yours
  18. It was working when it left the shop. Have you entered the Margin and dates?
  19. Output the link/s in the foreach loop foreach ($pdf_files as $pdf_file) { $pdfURL = $mediaUrl."".$pdf_file; $pdfPath = $mediapath .'/pdf_upload/' .$pdf_file; if($pdf_file != "" && file_exists($pdfPath)) echo "<div class='dz_pdf'> <a href='$pdfURL' download>$pdf_file</a> </div> "; } }
  20. Remove the default values and only process if ikke and dates have been provided. Revised: <?php require 'db_inc.php'; // USE YOUR OWN $con = myConnect('db2'); // CONNECTION CODE $ikke = $_GET['ikke'] ?? ''; $from = $_GET['start'] ?? ''; $to = $_GET['to'] ?? ''; $tdata = ""; if (!empty($from) && !empty($to) && !empty($ikke)) { $query = " SELECT reps.rep_name, p41Sales.totalrum, allSales.total FROM reps INNER JOIN ( SELECT reps.rep_id, sum(sales.sales_totaldollars) AS total FROM `sales` JOIN reps ON reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN ? AND ?) GROUP BY reps.rep_id ) allSales ON allSales.rep_id = reps.rep_id LEFT JOIN ( SELECT reps.rep_id, sum(salesdetails.salesdetails_pricedollars) AS totalrum FROM `sales` JOIN salesdetails ON salesdetails.salesdetails_salesticketnr = sales.sales_ticketnr JOIN reps ON reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN ? AND ?) AND salesdetails.salesdetails_productid IN (41,50,51,52,53,54,55,56) GROUP BY reps.rep_name ) p41Sales ON p41Sales.rep_id = reps.rep_id "; $result = mysqli_prepare($con,$query); $result->bind_param('ssss', $from, $to, $from, $to); $result->execute(); $result->bind_result($rep_name, $totalrum, $total); $totalcigars = 0; $totalcigarscomm = 0; $totalrums = 0; $totalrumscomm = 0; $totalsales = 0; $totalcomm = 0; $CigarMargin = floatval($ikke); $RumMargin = 1; while($row = $result->fetch()) { $tot = round($total * $CigarMargin); $rums = round($totalrum * $RumMargin); $cigars = $tot - $rums; $cigarscomm = $cigars * .3; $rumscomm = $rums * .3; $comm = $cigarscomm + $rumscomm; $totalcigars += $cigars; $totalcigarscomm += $cigarscomm; $totalrums += $rums; $totalrumscomm += $rumscomm; $totalsales += $tot; $totalcomm += $comm; $represent = explode(" ", $rep_name); $tdata .= sprintf("<tr> <td class='la'>%s</td> <td>%d</td> <td>%d</td> <td>%0.2f</td> <td>%d</td> <td>%0.2f</td> <td>%0.2f</td> </tr> ", $represent[0], $tot, $cigars, $cigarscomm, $rums, $rumscomm, $comm ); } $tdata .= sprintf("<tr class='tot'> <td class='la'>%s</td> <td>%d</td> <td>%d</td> <td>%0.2f</td> <td>%d</td> <td>%0.2f</td> <td>%0.2f</td> </tr> ", 'TOTALS', $totalsales, $totalcigars, $totalcigarscomm, $totalrums, $totalrumscomm, $totalcomm ); } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <title>Example</title> <style type='text/css'> table { width: 60%; border-collapse: collapse; margin: 20px auto; } th, td { padding: 4px 10px; } th { background-color: black; color: white; } td { text-align: right; } label { background-color: black; color: white; border: 1px solid white; display: inline-block; width: 80px; padding: 4px; } .la { text-align: left; } .tot { background-color: #666; color: white; } </style> </head> <body> <form method="GET"> <div class="col col-md-2"> <label for='ikke'>Margin %:</label> <input type="text" value="<?= $ikke ?>" name="ikke" id="ikke"> </div> <div class="col col-md-2"> <label for='start'>Date From:</label> <input type="date" value="<?= $from ?>" name="start" id="start" class="form-control"> </div> <div class="col col-md-2"> <label for='to'>Date To:</label> <input type="date" value="<?= $to ?>" name="to" id="to" class="form-control"> </div> <div> <input type='submit'> </div> </form> <div class="app-content content "> <table border='1' class="table dataTable" id="myTable2"> <thead> <tr> <th>Rep</th> <th>Sales</th> <th>Cigars</th> <th>30%</th> <th>Rum/Souv.</th> <th>30%</th> <th>Comm.</th> </tr> </thead> <tbody class="tbody"> <?= $tdata ?> </tbody> </table> </div> </body> </html>
  21. SELECT GROUP_CONCAT(merge.Description SEPARATOR '\n') ... Why the REPLACE() malarky? Just use the SEPARATOR option in GROUP_CONCAT(). SET @@group_concat_max_len = whatever;
  22. Something like this <?php require 'db_inc.php'; // USE YOUR OWN $con = myConnect('db2'); // CONNECTION CODE $ikke = $_GET['ikke'] ?? '0.455'; $from = $_GET['from'] ?? date('Y-m-d', strtotime('first day of this month')); $to = $_GET['to'] ?? date('Y-m-d'); $query = " SELECT reps.rep_name, p41Sales.totalrum, allSales.total FROM reps INNER JOIN ( SELECT reps.rep_id, sum(sales.sales_totaldollars) AS total FROM `sales` JOIN reps ON reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN ? AND ?) GROUP BY reps.rep_id ) allSales ON allSales.rep_id = reps.rep_id LEFT JOIN ( SELECT reps.rep_id, sum(salesdetails.salesdetails_pricedollars) AS totalrum FROM `sales` JOIN salesdetails ON salesdetails.salesdetails_salesticketnr = sales.sales_ticketnr JOIN reps ON reps.rep_id = sales.sales_repid AND reps.rep_touroperator_id = '5' AND reps.rep_active = 1 WHERE (sales.sales_date BETWEEN ? AND ?) AND salesdetails.salesdetails_productid = '41' OR salesdetails.salesdetails_productid = '56' OR salesdetails.salesdetails_productid = '55' OR salesdetails.salesdetails_productid = '54' OR salesdetails.salesdetails_productid = '53' OR salesdetails.salesdetails_productid = '52' OR salesdetails.salesdetails_productid = '51' OR salesdetails.salesdetails_productid = '50' GROUP BY reps.rep_name ) p41Sales ON p41Sales.rep_id = reps.rep_id"; $result = mysqli_prepare($con,$query); $result->bind_param('ssss', $from, $to, $from, $to); $result->execute(); $result->bind_result($rep_name, $totalrum, $total); $totalcigars = 0; $totalcigarscomm = 0; $totalrums = 0; $totalrumscomm = 0; $totalsales = 0; $totalcomm = 0; $CigarMargin = floatval($ikke); $RumMargin = 1; $tdata = ""; while($row = $result->fetch()) { $tot = round($total * $CigarMargin); $rums = round($totalrum * $RumMargin); $cigars = $tot - $rums; $cigarscomm = $cigars * .3; $rumscomm = $rums * .3; $comm = $cigarscomm + $rumscomm; $totalcigars += $cigars; $totalcigarscomm += $cigarscomm; $totalrums += $rums; $totalrumscomm += $rumscomm; $totalsales += $tot; $totalcomm += $comm; $represent = explode(" ", $rep_name); $tdata .= sprintf("<tr> <td class='la'>%s</td> <td>%d</td> <td>%d</td> <td>%0.2f</td> <td>%d</td> <td>%0.2f</td> <td>%0.2f</td> </tr> ", $represent[0], $tot, $cigars, $cigarscomm, $rums, $rumscomm, $comm ); } $tdata .= sprintf("<tr class='tot'> <td class='la'>%s</td> <td>%d</td> <td>%d</td> <td>%0.2f</td> <td>%d</td> <td>%0.2f</td> <td>%0.2f</td> </tr> ", 'TOTALS', $totalsales, $totalcigars, $totalcigarscomm, $totalrums, $totalrumscomm, $totalcomm ); ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <title>Example</title> <style type='text/css'> table { width: 60%; border-collapse: collapse; margin: 20px auto; } th, td { padding: 4px 10px; } th { background-color: black; color: white; } td { text-align: right; } .la { text-align: left; } .tot { background-color: #666; color: white; } </style> </head> <body> <form method="GET"> <div class="col col-md-2"> <label>Margin %:</label> <input type="text" value="<?= $ikke ?>"name="ikke" id="ikke"> </div> <div class="col col-md-2"> <label>Date From:</label> <input type="date" value="<?= $from ?>" name="start" id="start" class="form-control"> </div> <div class="col col-md-2"> <label>Date To:</label> <input type="date" value="<?= $to ?>" name="to" id="to" class="form-control"> </div> <div> <input type='submit'> </div> </form> <div class="app-content content "> <table border='1' class="table dataTable" id="myTable2"> <thead> <tr> <th>Rep</th> <th>Sales</th> <th>Cigars</th> <th>30%</th> <th>Rum/Souv.</th> <th>30%</th> <th>Comm.</th> </tr> </thead> <tbody class="tbody"> <?= $tdata ?> </tbody> </table> </div> </body> </html>
  23. In the above, "=" should be "==". If you use "=" you assign "" to the variable clearing any value it had.
  24. Whether you do that or not, you should still validate user input on the server (ie PHP) as there is no guarantee it came via your form.
×
×
  • 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.