-
Posts
24,607 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
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
-
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
-
How to change style when hover over div inside svg element?
Barand replied to eaglehopes's topic in CSS Help
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> -
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.
-
Where did datatables suddenly appear? All your previous code has shown you generating the table in PHP
-
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.
-
Oh!
-
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>
-
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 – $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>
-
If you are reformatting the date in PHP, what are you trying to do with it in Javascript?
-
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 | +------------+
-
-
-
Magento 2 Product PDF Download (Instructions etc)
Barand replied to Jules72's topic in PHP Coding Help
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> "; } } -
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>
-
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;
-
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>
-
Hello guys, I have a message error on my PHP code :
Barand replied to gildas-Milandou's topic in Applications
In the above, "=" should be "==". If you use "=" you assign "" to the variable clearing any value it had.- 1 reply
-
- 1
-
-
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.
-
Which page is supposed to process the from and to dates? Your form would send those values (and the ikke value) to "response.php" using POST method - if it were ever to be submitted (with a submit button or via a script) Your jquery sends the values date values only to "test.php" using GET method (ie in the query string). Why both the form and the jquery? Also if you use the GET method, you wshould process the received data from $_GET; with POST method you should process $_POST data. Use the GET method when you re GETTING data to display. Use POST when you want to do something with side-effects (like updating a database or logging in etc) Construct you pages with the php first followed by the html ... <?php process POST data - validation and db updates process GET data - build output from any queries ?> html output
-
How to select option if value is 'exactly' the string?
Barand replied to simona6's topic in Javascript Help
let $option = $("option[value='America']") $option.attr('disabled',true) -
How to select option if value is 'exactly' the string?
Barand replied to simona6's topic in Javascript Help
Equals? -
Putting normalization aside for now, you are getting those duplicate field values because you are using fetch_array(). This returns an array for each row in the results with both column names and column numbers as keys. Better to use fetch assoc() to get arrays with just the column names as keys. Your query selects a column called "original_name". That does not appear in any of your column name images.
-
I've been looking at the table structures. TOUROPERATORS (The one you got right.) +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | touroperator_id | int(11) | NO | PRI | NULL | auto_increment | | touroperator_name | varchar(255) | NO | | NULL | | | touroperator_active | tinyint(1) | NO | | 0 | | +---------------------+--------------+------+-----+---------+----------------+ REPS +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | rep_id | int(11) | NO | PRI | NULL | auto_increment | | rep_name | varchar(255) | NO | | NULL | | | rep_touroperator_id | int(255) | NO | MUL | 0 | | should be INT, should be indexed | rep_active | tinyint(1) | NO | | 0 | | | rep_ot | tinyint(1) | NO | | NULL | | +---------------------+--------------+------+-----+---------+----------------+ SALES +----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------+--------------+------+-----+---------+-------+ | sales_ticketnr | varchar(255) | YES | UNI | NULL | | should be INT, should be primary key | sales_date | varchar(10) | YES | | NULL | | should be type DATE | sales_employeeid | varchar(255) | YES | MUL | NULL | | INT, should be indexed | sales_repid | varchar(255) | YES | MUL | NULL | | INT, should be indexed | sales_totaldollars | varchar(255) | YES | | NULL | | INT | sales_paiddollars | varchar(255) | YES | | NULL | | INT | sales_paidpesos | varchar(255) | YES | | NULL | | INT | sales_paideuros | varchar(255) | YES | | 0 | | INT | sales_paidcreditcard | varchar(255) | YES | | | | INT | sales_active | tinyint(4) | NO | | 1 | | +----------------------+--------------+------+-----+---------+-------+ SALESDETAILS +----------------------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------------------+------------+------+-----+---------+----------------+ | salesdetails_id | int(255) | NO | PRI | NULL | auto_increment | 255 digits is a lot of ids, if you could store a nuber that big! INT(11) | salesdetails_salesticketnr | text | NO | | NULL | | INT(11), not TEXT, should be indexed | salesdetails_amount | int(255) | NO | | NULL | | INT(11) | salesdetails_productid | int(255) | NO | MUL | NULL | | INT(11), should be indexed | salesdetails_pricedollars | int(255) | NO | | NULL | | INT(11) | salesdetails_active | tinyint(1) | NO | | 1 | | +----------------------------+------------+------+-----+---------+----------------+ SALESARIMAR +--------------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------------+---------+------+-----+---------+----------------+ | sales_id | int(11) | NO | PRI | NULL | auto_increment | | sales_date | text | NO | | NULL | | DATE type | sales_ticketnr | int(11) | NO | | NULL | | should be indexed | sales_employeeid | int(11) | NO | | NULL | | should be indexed | sales_repid | int(11) | NO | | NULL | | should be indexed | sales_totaldollars | int(11) | NO | | NULL | | +--------------------+---------+------+-----+---------+----------------+
-
The only change from before is that the tour operator is now 12, so I don't know why you got no results.