Jump to content

Search the Community

Showing results for tags 'parent/child menu'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi all, I have the following code to add the id and parent_id of a menu item from one table (nodes ) to another table (roleMenu ) when a checkbox is checked in the menu options . If successful the response is permissionGranted (sent via ajax). I am using a recursive function to do this. The problem is if a child is added (checkbox is checked) where the parent was not previously added, both the child and parent menu items are added but the response is not echoed. I have attached images of the nodes table, roleMenu table and the menu of checkbox options. Can anyone help with my code below? - or - if you think of a better way to do this I am open to suggestions. I've worked on this for several hours but no luck. Any help would be greatly appreciated. Thanks. if ($action == "grantAccess") { function addMenuItems($userRoleValue, $pageIdValue) { include ('include/dbconnect.php'); try { $pdo = new PDO ("mysql:host=$dbhost;dbname=$dbname","$dbusername","$dbuserpass"); } catch (PDOException $e) { echo "Failed to get DB handle: " . $e->getMessage() . "\n"; exit; } $queryRoleParents = $pdo->prepare("SELECT id, parent_id FROM nodes WHERE id = \"$pageIdValue\""); $queryRoleParents->execute(); while($row = $queryRoleParents->fetch()) { if($row['parent_id'] == 0) { $queryRoleItem = $pdo->prepare("SELECT * FROM roleMenu WHERE menuid = \"$pageIdValue\" AND role = \"$userRoleValue\""); $queryRoleItem->execute(); $countRoleItem = $queryRoleItem->rowCount(); if($countRoleItem == 0) { $grantPageAccess = $pdo->prepare("INSERT INTO roleMenu (rmid, role, menuid, parent_id) VALUES ('', \"$userRoleValue\", \"$pageIdValue\", ".$row['parent_id'].")"); if ($grantPageAccess->execute()) { echo "permissionGranted"; } else { echo "permissionFailed"; } } } else { $queryRoleItem = $pdo->prepare("SELECT * FROM roleMenu WHERE menuid = \"$pageIdValue\" AND role = \"$userRoleValue\""); $queryRoleItem->execute(); $countRoleItem = $queryRoleItem->rowCount(); if($countRoleItem == 0) { $grantPageAccess = $pdo->prepare("INSERT INTO roleMenu (rmid, role, menuid, parent_id) VALUES ('', \"$userRoleValue\", \"$pageIdValue\", ".$row['parent_id'].")"); if ($grantPageAccess->execute()) { echo "permissionGranted"; } else { echo "permissionFailed"; } addMenuItems($userRoleValue, $row['parent_id']); } } } } return addMenuItems($userRoleValue, $pageIdValue); }
×
×
  • 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.