Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. OK - I've added the sort usort($test, fn($a, $b) => $b['itemCount']<=>$a['itemCount']); // sort descending itemCount $seen = []; foreach ($test as $k => &$rec) { $rec['rolanID'] = array_diff($rec['rolanID'], $seen); // find new ids if ($rec['rolanID']) { // if there are some new ones ... $rec['itemCount'] = count($rec['rolanID']); // count them $seen = array_merge($seen, $rec['rolanID']); // add the new ones to those already seen } else unset($test[$k]); // if no ids, remove the array item } and I now get this (no duplicate 123)... Array ( [0] => Array ( [supplier] => TEST2 DEPO [rolanID] => Array ( [0] => 456 [1] => 188 [2] => 200 [3] => 123 ) [itemCount] => 4 ) [1] => Array ( [supplier] => TEST DEPO [rolanID] => Array ( [1] => 234 ) [itemCount] => 1 ) [2] => Array ( [supplier] => DIFFERENT DEPO [rolanID] => Array ( [0] => 897 [1] => 487 [2] => 100 ) [itemCount] => 3 ) )
  2. Using your new $test array with my code, I get this in the $test array... Array ( [0] => Array ( [supplier] => ROLAN [rolanID] => Array ( [0] => 456 ) [itemCount] => 1 ) [1] => Array ( [supplier] => ROLAN [rolanID] => Array ( [0] => 123 [1] => 234 ) [itemCount] => 2 ) [3] => Array ( [supplier] => DIFFERENT DEPO [rolanID] => Array ( [0] => 897 [1] => 487 [2] => 100 ) [itemCount] => 3 ) [4] => Array ( [supplier] => TEST2 DEPO [rolanID] => Array ( [1] => 188 [2] => 200 ) [itemCount] => 2 ) )
  3. Yes, you could.
  4. Does output of your $_GET array show an "id" key? echo '<pre>' . print_r($_GET, true) . '</pre>';
  5. Here's my solution $seen = []; foreach ($test as $k => &$rec) { $rec['rolanID'] = array_diff($rec['rolanID'], $seen); // find new ids if ($rec['rolanID']) { // if there are some new ones ... $rec['itemCount'] = count($rec['rolanID']); // count them $seen = array_merge($seen, $rec['rolanID']); // add the new ones to those already seen } else unset($test[$k]); // if no ids, remove the array item } +-----------------------------------------------+ | | | $test ARRAY - AFTER | | | +-----------------------------------------------+ | | | Array | | ( | | [0] => Array | | ( | | [supplier] => TEST DEPO | | [rolanID] => Array | | ( | | [0] => 123 | | [1] => 234 | | [2] => 456 | | ) | | | | [itemCount] => 3 | | ) | | | | [1] => Array | | ( | | [supplier] => ANOTHER DEPO | | [rolanID] => Array | | ( | | [1] => 786 | | [2] => 345 | | ) | | | | [itemCount] => 2 | | ) | | ) | | | +-----------------------------------------------+
  6. I feel your pain. Fetch syntax is far too cryptic for me.
  7. Google turned up this https://rapidapi.com/guides/fetch-api-async-await
  8. Yes - line 7. Plus it's normal to specify a default database. Depends what you want to do with it and what operating system you are using.
  9. Is there an item in your $_GET array with the key "c.id"? I suspect it will be just $_GET["id"] as you were originally using.
  10. Would this work? $results = array_filter($results, fn($v) => in_array($v->iso_639_1, ['en','fr']) && $v->type == 'Trailer' && $v->site == 'YouTube' ); rsort($results); // 'fr' first then 'en' results foreach ($results as $r) { echo "{$r->iso_639_1} &ndash; {$r->name}<br>"; }
  11. I can't imagine anyone attempting to edit that amount of pastebin data to make it suitable to test any solution. Post a json_encoded version of the array here so we have something useable. PS and post the code you have so far - it may give us a clue to what you are talking about.
  12. Breakfast and two coffees in the morning are my minimum requirement.
  13. You find that out with a process commonly known as "testing" (You might want to Google that)
  14. The one with braces will work, the other won't even run.
  15. If that's how you want the layout to look. Only you know that.
  16. Then append those to the content too.
  17. Similar data but solution is more complicated with this one
  18. You have a form which has been designed to produce invoices one month at a time - there is only the option to enter a singlw month First thing to do is redesign the form to allow the specification of multiple months. For example a month menu allowing multiple selections, or 12 checkboxes, or have fields to specify number of months and starting month (4 months starting at August) Then change the processing of the submitted form to produce the invoice records for those months.
  19. Don't use 2 queries when 1 will do SELECT c.id , c.name , c.last_name , c.mobile_number , c.status , a.username as mentorname FROM contacts c LEFT JOIN accounts a ON c.mentor = a.id WHERE c.id = 1; +----+-------+-----------+---------------+---------+------------+ | id | name | last_name | mobile_number | status | mentorname | +----+-------+-----------+---------------+---------+------------+ | 1 | Scott | Chegg | 01012345678 | current | jbloggs | +----+-------+-----------+---------------+---------+------------+
  20. Barand

    Hello!!!

    I see you joined in 2003 - experience is always welcome.
  21. It's the append that makes the difference. Your solution was always overwriting the product id that that was there.
  22. All you need to do is loop through your original array using foreach() and append the products to a new array, providing the required key values. foreach ($orig as $rec) $new[ $rec['supplier'] ]['productID'][] = $rec['part_id']; Result for $new Array ( [COOLDRIVE DISTRIBUTION] => Array ( [productID] => Array ( [0] => 2338117 ) ) [ROLAN] => Array ( [productID] => Array ( [0] => 2338117 [1] => 51154 ) ) )
  23. PS If you really want to do it in PHP then you can apply the same method to an array $thresholds = array( '-' => [0, 100], 'contributor' => [101, 1000], 'author' => [1001, 10000], 'editor' => [10001, 100000], 'administrator' => [100001, 999999999] ); echo getUserRole(50000, $thresholds); //--> editor function getUserRole($current_balance, $thresholds) { foreach ( $thresholds as $role => $range ) { if ( $range[0] <= $current_balance && $current_balance <= $range[1] ) { return $role; } } return false; }
  24. With a couple of db tables like this Table: user Table: role +---------+----------+--------+ +---------+---------------+-----------+------------+ | user_id | username | points | | role_id | role_name | point_min | points_max | +---------+----------+--------+ +---------+---------------+-----------+------------+ | 1 | John | 66 | | 5 | - | 0 | 100 | | 2 | Paul | 101 | | 6 | Contributor | 101 | 1000 | | 3 | George | 3000 | | 7 | Author | 1001 | 10000 | | 4 | Ringo | 200000 | | 8 | Editor | 10001 | 100000 | +---------+----------+--------+ | 9 | Administrator | 100001 | 999999999 | +---------+---------------+-----------+------------+ Then a simple query SELECT username , rolename FROM user u JOIN role r ON u.points BETWEEN r.points_min AND r.points_max; does the job for you +----------+---------------+ | username | rolename | +----------+---------------+ | John | - | | Paul | Contributor | | George | Author | | Ringo | Administrator | +----------+---------------+
×
×
  • 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.