-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
When you click the "View" button you go to "newdisplay.php". What is the value of the id in address bar at the top? Does it match the one you clicked? What are doing with that id value that is passed to the page? (The code?) [edit...] After a closer look at you link I see it contains a submit input. WHY? Is that taking precedence and just reloading the page? What happens if the link is <a href='newdisplay.php?id=$result[id]'>View<a/>
-
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
If I reverse the array (to give the same order that your sort is giving - DIFFERENT DEPO before TEST DEPO) I get Array ( [0] => Array ( [supplier] => TEST2 DEPO [rolanID] => Array ( [0] => 456 [1] => 188 [2] => 200 [3] => 123 ) [itemCount] => 4 ) [1] => Array ( [supplier] => DIFFERENT DEPO [rolanID] => Array ( [0] => 897 [1] => 487 [2] => 100 ) [itemCount] => 3 ) [2] => Array ( [supplier] => TEST DEPO [rolanID] => Array ( [1] => 234 ) [itemCount] => 1 ) ) -
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
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 ) ) -
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
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 ) ) -
Yes, you could.
-
Does output of your $_GET array show an "id" key? echo '<pre>' . print_r($_GET, true) . '</pre>';
-
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
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 | | ) | | ) | | | +-----------------------------------------------+ -
I feel your pain. Fetch syntax is far too cryptic for me.
-
Google turned up this https://rapidapi.com/guides/fetch-api-async-await
-
how to connect php to mysql (any errors in code?)
Barand replied to duchaine1's topic in PHP Coding Help
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. -
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.
-
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} – {$r->name}<br>"; }
-
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.
-
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
Breakfast and two coffees in the morning are my minimum requirement. -
You find that out with a process commonly known as "testing" (You might want to Google that)
-
The one with braces will work, the other won't even run.
-
If that's how you want the layout to look. Only you know that.
-
Then append those to the content too.
-
How to manipulate multi-dimension array in PHP?
Barand replied to soyaslim's topic in PHP Coding Help
Similar data but solution is more complicated with this one -
How to submit a form in php multiple times with a single submit button
Barand replied to alir22456's topic in PHP Coding Help
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.