Server IP : 184.154.167.98 / Your IP : 18.116.19.19 Web Server : Apache System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 User : puertode ( 1767) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/puertode/public_html/oficios/sis/ |
Upload File : |
<?php // (A) CONNECT TO DATABASE - CHANGE SETTINGS TO YOUR OWN! $dbHost = "localhost"; $dbName = "puertode_registro"; $dbChar = "utf8"; $dbUser = "puertode_registro"; $dbPass = "Ryogoku21@"; try { $pdo = new PDO( "mysql:host=$dbHost;dbname=$dbName;charset=$dbChar", $dbUser, $dbPass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ] ); } catch (Exception $ex) { exit($ex->getMessage()); } // (B) DRILL DOWN GET MENU ITEMS // ARRANGE BY [PARENT ID] => [MENU ITEMS] $items = []; while (true) { // (B1) SQL QUERY $sql = "SELECT * FROM `menu_items` WHERE `parent_id` "; if (!isset($next)) { $sql .= "IS NULL"; } else { $sql .= "IN ($next)"; } // (B2) FETCH MENU ITEMS $next = ""; $parent = ""; $stmt = $pdo->prepare($sql); $stmt->execute(); while (($i = $stmt->fetch()) !== false) { $parent = $i['parent_id']=="" ? 0 : $i['parent_id'] ; if (!isset($items[$parent])) { $items[$parent] = []; } $items[$parent][$i['item_id']] = $i; $next .= $i['item_id'] . ","; } if ($next == "") { break; } else { $next = substr($next, 0, -1); } } // (C) CLOSE DATABASE CONNECTION $stmt = null; $pdo = null;