Jump to content

Barand

Moderators
  • Posts

    24,285
  • Joined

  • Last visited

  • Days Won

    787

Everything posted by Barand

  1. or UPDATE portal_content SET portal_content_json = JSON_SET(portal_content_json, '$."Portal Content"."Colours"."primary"', 'limegreen', '$."Portal Content"."Colours"."secondary"', 'hotpink'), '$."Portal Content"."Colours"."tertiary"', 'orange') WHERE `portal_attachment_id` = 25 ; When all else fails... https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html
  2. This is the update example from my earlier post UPDATE json_test SET jstuff = JSON_SET(jstuff, '$."card".4."cardName"', 'This is a different card') WHERE id = 1; Note use of ' and " . I'll need to experiment further. One way would be to update all colors in one JSON_SET UPDATE portal_content SET portal_content_json = JSON_SET(portal_content_json, '$."Portal Content"."Colours"', '{"primary":"limegreen", "secondary":"hotpink", "tertiary":"orange", "quaternary":"lavender"}') WHERE `portal_attachment_id` = 25;
  3. Yes, JSON is picky when it comes to single and double quotes preferring "" inside the JSON.
  4. Yes - the code I told you to use instead. You'll benefit more if you read the replies.
  5. You must be using an outdated version of php. Str_starts_with() requires version 8. Use this instead $required = array_filter($files, fn($v)=>substr($v, 0, 5) == 'alg00');
  6. Easier with str_starts_with() $files = [ 'alg001.php', 'alg002.php', 'alg003.php', 'alg004.php', 'alg005.php', 'algComp.php', 'ranFrac.php', 'ranalg.php', 'randec.php', 'randint.php' ]; $required = array_filter($files, fn($v)=>str_starts_with($v, 'alg00')); echo '<pre>' . print_r($required, 1) . '</pre>'; Gives Array ( [0] => alg001.php [1] => alg002.php [2] => alg003.php [3] => alg004.php [4] => alg005.php )
  7. $radint = mt_rand(1,33); $flip = mt_rand(1,2); $radint *= ($flip == 2) ? -1 : 1;
  8. A string can be treated as an array of characters, so str = 'HELLO' console.log(str[0]) //==> H console.log(str[2]) //==> L console.log(str[4]) //==> O
  9. It will if you declare the number as a string eg const str = '98765'; gives
  10. Because you increment "i" twice inside the loop. Remove ++i. When I run the script it gives "hellohellohello" try <script type='text/javascript'> const str = 'HELLO'; let i = 0 let result = "" while (i < str.length) { result = result + str[i].toLowerCase() console.log(result) i++ } </script>
  11. Have you got php error reporting turned on? mysqli error reporting turned on? Have you checked error logs (on web server errors should be logged and not reported)?
  12. Formats the output as a left-aligned 35 char wide string and a right-aligned 5 digit wide number. https://www.php.net/printf
  13. You've done the hard work already. Instead of calculating the product, store the selected array. <?php $primes = array(2, 3, 5, 7, 11, 13, 17, 19, 23); $combos = []; function getAllCombinations($arr, $n, &$combos, $selected = array(), $startIndex = 0) { if ($n == 0) { $combos[] = $selected; // $product = 1; // foreach ($selected as $prime) { // $pr[] = $prime; // $product *= $prime; // $pr[] = $prime; // } // echo "Product: $product\n"; return; } for ($i = $startIndex; $i < count($arr); $i++) { $selected[] = $arr[$i]; getAllCombinations($arr, $n - 1, $combos, $selected, $i + 1); array_pop($selected); // Backtrack and remove the element for next iteration } } getAllCombinations($primes, 4, $combos); echo '<pre>'; foreach ($combos as $com) { printf("%-35s = %5d<br>", join(' &times; ', $com), array_product($com)); // output numbers and product } ?> giving 2 × 3 × 5 × 7 = 210 2 × 3 × 5 × 11 = 330 2 × 3 × 5 × 13 = 390 2 × 3 × 5 × 17 = 510 2 × 3 × 5 × 19 = 570 2 × 3 × 5 × 23 = 690 2 × 3 × 7 × 11 = 462 2 × 3 × 7 × 13 = 546 2 × 3 × 7 × 17 = 714 2 × 3 × 7 × 19 = 798 2 × 3 × 7 × 23 = 966 2 × 3 × 11 × 13 = 858 2 × 3 × 11 × 17 = 1122 2 × 3 × 11 × 19 = 1254 2 × 3 × 11 × 23 = 1518 2 × 3 × 13 × 17 = 1326 2 × 3 × 13 × 19 = 1482 2 × 3 × 13 × 23 = 1794 2 × 3 × 17 × 19 = 1938 2 × 3 × 17 × 23 = 2346 2 × 3 × 19 × 23 = 2622 2 × 5 × 7 × 11 = 770 2 × 5 × 7 × 13 = 910 . . 5 × 17 × 19 × 23 = 37145 7 × 11 × 13 × 17 = 17017 7 × 11 × 13 × 19 = 19019 7 × 11 × 13 × 23 = 23023 7 × 11 × 17 × 19 = 24871 7 × 11 × 17 × 23 = 30107 7 × 11 × 19 × 23 = 33649 7 × 13 × 17 × 19 = 29393 7 × 13 × 17 × 23 = 35581 7 × 13 × 19 × 23 = 39767 7 × 17 × 19 × 23 = 52003 11 × 13 × 17 × 19 = 46189 11 × 13 × 17 × 23 = 55913 11 × 13 × 19 × 23 = 62491 11 × 17 × 19 × 23 = 81719 13 × 17 × 19 × 23 = 96577
  14. Before I retired (approx 12 years ago) I regularly worked on a windows based intranet. I found the ADLDAP class a great tool. In fact the system admins used to ask me to create reports that they couldn't accesss via their Microsoft network tools. https://github.com/adldap/adLDAP
  15. As you are sending data via the url querystring you should be using $_GET, not $_POST. Key/value pairs in the querystring should not be comma-separated
  16. Put this line mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); just before your "$conn = new mysqli(...)" and see what the error message says when you attempt the insert.
  17. Barand

    Report

    As the data I was given has no data for RAGUL's empno in any tables (except usertable) I cannot verify any of my theories on what may be wrong. Also for branch 2 I have only this... +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | month | name | CustomerTotal | CustomerActual | ProductionTotal | ProductionActual | MarketingTotal | MarketingActual | +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | 2024-03 | Palanikumar B | | | | | 1 | | | 2024-02 | NAVEENKUMAR P | | | | | 1 | | +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ For branch 5... +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | month | name | CustomerTotal | CustomerActual | ProductionTotal | ProductionActual | MarketingTotal | MarketingActual | +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | 2024-02 | Nethaji.MK | | | | | 1 | | | 2024-02 | T.Anandakrishnan | | | | | 1 | | | 2024-02 | Sivanraj.A | | | | | 1 | | | 2024-02 | kannan.r | | | | | 1 | | | 2024-01 | thayyanayaki | 5 | 5 | 2 | 2 | | | | 2024-02 | thayyanayaki | 5 | 5 | 2 | 2 | | | | 2024-03 | thayyanayaki | 5 | 5 | 2 | 2 | 1 | | | 2024-04 | thayyanayaki | 5 | 3 | 2 | 1 | | | | 2024-01 | Vignesh.M | | | | | 1 | 1 | | 2024-02 | Vignesh.M | | | | | 1 | | | 2024-02 | N.Manikandan | | | | | 1 | | | 2024-02 | Dinesh.C | | | | | 1 | | +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ The previous queries (your and mine) would only report on whatever empno, branch and month values existed in the production table (the one that isn't LEFT JOINED). This version removes that reliance ... SELECT u.Month , Name , CustomerTotal , CustomerActual , ProductionTotal , ProductionActual , MarketingTotal , MarketingActual FROM ( WITH RECURSIVE allmonths (id, month) as ( SELECT 1, '2024-01' UNION ALL SELECT id+1, concat('2024-', lpad(id+1,2,'0')) FROM allmonths WHERE id < 4 ) SELECT empNo as empId , fname as name , month , ? as branch FROM usertable, allmonths -- WHERE role IN (4, 5) ) u LEFT JOIN ( SELECT count(*) as CustomerTotal , sum(VisitType = 'No Due' OR VisitDate != '') as CustomerActual , month , empid , branch FROM customerdata GROUP BY month,branch,empid ) ca ON u.month = ca.month AND u.empid = ca.empid AND u.branch = ca.branch LEFT JOIN ( SELECT count(*) as ProductionTotal , sum(MCubicmeter OR MHourmeter) as ProductionActual , month , empid , branch FROM production GROUP BY month, branch, empid ) pa ON u.month = pa.month AND u.empid = pa.empid AND u.branch = pa.branch LEFT JOIN ( SELECT count(*) as MarketingTotal , month , empid , branch FROM marketing_target GROUP BY month, branch, empid ) mt ON u.month = mt.month AND u.empid = mt.empid AND u.branch = mt.branch LEFT JOIN ( SELECT count(*) as MarketingActual , month , empid FROM marketing_data GROUP BY month, empid ) ma ON u.month = ma.month AND u.empid = ma.empid AND u.branch = mt.branch HAVING CustomerTotal OR CustomerActual OR ProductionTotal OR ProductionActual OR MarketingTotal OR MarketingActual ORDER BY u.empid, u.month;
  18. add this and job almost done... $tot = array_sum($counts); $pcents = array_map(fn($v)=>$v*100/$tot, $counts);
  19. Try something like... $urls = array_column($statement->fetchAll(), 'domain_names'); $tlds = array_map(fn($v)=>strstr($v, '.'), $urls); $counts = array_count_values($tlds);
  20. You may echo all of them but, each time through the loop, $tld is overwritten - you are just left with last one.
  21. Took a fair bit of experimenting to get the right incantations for the update, but... Data SELECT * FROM json_test; +----+-------------------------------------------------------------------------------------------------------------------------------+ | id | jstuff | +----+-------------------------------------------------------------------------------------------------------------------------------+ | 1 | {"card": {"4": {"cardName": "This is a card", "iconSelection": "1", "linkLocation": "5", "paragraph": "This is para"}}} | +----+-------------------------------------------------------------------------------------------------------------------------------+ Update UPDATE json_test SET jstuff = JSON_SET(jstuff, '$."card".4."cardName"', 'This is a different card') WHERE id = 1; Check SELECT * FROM json_test; +----+-----------------------------------------------------------------------------------------------------------------------------------+ | id | jstuff | +----+-----------------------------------------------------------------------------------------------------------------------------------+ | 1 | {"card": {"4": {"cardName": "This is a different card", "iconSelection": "1", "linkLocation": "5", "paragraph": "This is para"}}} | +----+-----------------------------------------------------------------------------------------------------------------------------------+
  22. ... then what do think that is on line 4?
  23. Barand

    Report

    I thought I had. Read my replies, which were... You are joining on "month" so if different subqueries are selecting different months, then they aren't going to match. Your marketing table is missing 2024-04 data so you aren't going to get any totals from that table for that month. Do you need me to spell it out in more detail and make it clearer? I had a go at rewriting your query with simple subquery for each total SELECT ca.Month , Name , CustomerTotal , CustomerActual , ProductionTotal , ProductionActual , MarketingTotal , MarketingActual FROM ( SELECT empNo as empId , fname as name FROM usertable WHERE role IN (4, 5) ) u JOIN ( SELECT count(*) as CustomerTotal , sum(VisitType = 'No Due' OR VisitDate != '') as CustomerActual , month , empid , branch FROM customerdata GROUP BY month,branch,empid ) ca USING (empid) LEFT JOIN ( SELECT count(*) as ProductionTotal , sum(MCubicmeter OR MHourmeter) as ProductionActual , month , empid , branch FROM production GROUP BY month, branch, empid ) pa USING (month, branch, empid) LEFT JOIN ( SELECT count(*) as MarketingTotal , month , empid , branch FROM marketing_target GROUP BY month, branch, empid ) mt USING (month, branch, empid) LEFT JOIN ( SELECT count(*) as MarketingActual , month , empid FROM marketing_data GROUP BY month, empid ) ma USING (month, empid) WHERE ca.branch = '5' AND ca.month = '2024-04' ;
×
×
  • 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.