Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:56:58+00:00 2026-06-10T06:56:58+00:00

Bellow is the code for a custom module that parses json to ios devices.

  • 0

Bellow is the code for a custom module that parses json to ios devices. The thing is on my drupal page I’ve created a node hierarcy using “nodehierarcy” module. I’ve got two types of custom contents – phones and events. For each phone I have a list of events which I want to parse. The problem with the code below is that it’s parsing all of the jobs instead of categorizing them per device. The json output url is: “xyz.com/job/json”. But I want something like xyz.com/?q=node/4/json, node 4 representing a phone. Any ideas?

function job_menu() {
    $items =array();

    $items['job/json'] = array(
        'title' => 'Json callback',
        'page callback' => 'message_json_page',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );
    return $items;   
}

function message_json_page(){
    $sql = "SELECT n.nid , n.title as name FROM {node} n 
            WHERE n.status = 1 and n.type = :type";
    $result = db_query($sql, array(':type'=>'job'))->fetchAll();
    $json_value = json_encode($result);
    print $json_value;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:56:59+00:00Added an answer on June 10, 2026 at 6:56 am

    Paths in Drupal go one of two ways…if you have clean URLs enabled then you’ll access a page at something like mysite.com/node/4/json. If you don’t have clean URLs on you’ll access the same page at mysite.com?q=node/4/json (which as it happens is exactly what you’re after).

    That in mind, you would set up a menu item for node/*/json, and use some of the node hierarchy internal functions to get a list of the children nodes in your page callback:

    function job_menu() {
      $items['node/%node/json'] = array(
        'title' => 'Json callback',
        'page callback' => 'message_json_page',
        'page arguments' => array(1),
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
      );
      return $items;
    }
    
    function message_json_page($node) {
      $children_links = _nodehierarchy_get_children_menu_links($node->nid, FALSE);
    
      $nids = array();
      foreach ($children_links as $child_link) {
        list(, $nid) = explode('/', $child_link['link_path']);
        $nids[] = $nid;
      }
    
      $sql = "SELECT n.nid , n.title as name FROM {node} n WHERE n.nid in (:nids) AND n.status = 1 and n.type = :type";
      $result = db_query($sql, array('nids' => $nids, ':type'=>'job'))->fetchAll();
    
      $json_value = json_encode($result);
      print $json_value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a custom function shown below with code I copied from a button
work on asp.net vs 05 C#.Master page header contain the bellow code <script type=text/javascript
Im created a custom block, with the below code, but im having some trouble
The code below successfully recognizes internal classes which are decorated with my custom Module
I'm looking for a google search module that uses the 'Google Custom Search API'
I have created custom attributes for a category in my module's install script like
I have a django app that uses a custom middleware module to create a
I have the below code, which iterates over a list based on a custom
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I'm trying to create a custom drop down and using the code below it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.