Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/30/2021 in all areas

  1. Create an intermediate array which restructures your data foreach ($array as $a) { if (!isset($new[$a['u1']])) { $new[$a['u1']] = []; } $new[$a['u1']][] = $a['u2']; } which gives $new array ... Array ( [6] => Array ( [0] => 4 [1] => 3 [2] => 3 [3] => 4 [4] => 11 [5] => 11 ) [3] => Array ( [0] => 4 [1] => 11 [2] => 11 [3] => 4 ) [4] => Array ( [0] => 11 [1] => 11 ) ) Now it's simple to loop through outputting the rows and columns.
    1 point
  2. No need to do that when you can calculate them... function bankHols($yr) { // CALC PUBLIC HOLS FOR $yr $hols = array(); $newyr = "$yr-01-01"; switch (date('w', strtotime($newyr))) { case 6: $newyr = "{$yr}-01-03"; break; case 0: $newyr = "{$yr}-01-02"; break; } $hols['New Year'] = $newyr; $easter = easter_date($yr); $hols['Easter'] = array(date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter))); $mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d'); $hols['May Day'] = $mayday; $sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d'); $hols['Spring Bank'] = $sbank; $abank = (new DateTime("last monday of august $yr"))->format('Y-m-d'); $hols['August Bank'] = $abank; $x1 = "$yr-12-25"; $x2 = "$yr-12-26"; switch (date('w', strtotime($x1))) { case 5: $x2 = "$yr-12-28"; break; case 6: $x1 = "$yr-12-27"; $x2 = "$yr-12-28"; break; case 0: $x1 = "$yr-12-26"; $x2 = "$yr-12-27"; break; } $hols['Christmas'] = array($x1,$x2); return $hols; } $holidays = bankHols(2021);
    1 point
  3. Forget the above. I have now realized that I completely missed that your module_access on had links to the 2 parent modules. Here's an alternative approach $uID = 1; $res = $con->prepare("SELECT m1.mod_name as name1 , m2.mod_name as name2 , m2.link as link2 FROM module m1 JOIN module m2 ON m1.mid = m2.parent_id JOIN module_access ma ON (m1.mid = ma.page_id) WHERE ma.user=? ORDER BY m1.mid "); $res->execute([$uID]); $mods = []; foreach ($res as $row) { if (!isset($mods[$row['name1']])) { $mods[$row['name1']] = []; } $mods[$row['name1']][$row['name2']] = $row['link2'] ; } The mods array now contains... Array ( [Sales] => Array ( [Quotes] => quotes.php [Clients] => clients.php ) [Finance] => Array ( [Invoices] => invoices.php [Expense] => expenses.php [Taxes] => taxes.php ) ) ... which you can loop through to give the output function showMenu(&$arr) { echo "<ul>\n"; foreach($arr as $parent => $modules) { echo "<li class='li0'>$parent\n"; echo "<ul>\n"; foreach ($modules as $name => $link) { echo "<li class='li1'><a href='$link'>$name</a>\n"; } echo "</ul>\n"; echo "</li>\n"; } echo "</ul>\n"; } giving
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • 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.