Jump to content

Barand

Moderators
  • Posts

    24,285
  • Joined

  • Last visited

  • Days Won

    788

Barand last won the day on March 18

Barand had the most liked content!

About Barand

Profile Information

Recent Profile Visitors

95,422 profile views

Barand's Achievements

Prolific Member

Prolific Member (5/5)

2.1k

Reputation

466

Community Answers

  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
×
×
  • 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.