Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello Couchies!

I am trying to generate a JSON to output a specific employee of a specific department.

I have a code to generate the JSON (thanks to @bartonsweb and @trendoman) through which I can output the entire list of employees available, at once.

Code: Select all
<?php require_once( '../cms.php' ); ?>
   <cms:content_type 'application/json'/>
   <cms:set deptId="<cms:gpc 'deptId' method='get' />" />
   
   <cms:set dept_count='0' scope='global' />
   <cms:if deptId >
      <cms:query sql="SELECT id AS `k_folder_id`,  name AS `k_folder_name`, title AS `k_folder_title` FROM `couch_folders` AS f WHERE f.id = '<cms:show deptId />' AND f.template_id = '1'" limit='1'>
         <cms:set selected_folder = k_folder_name scope='global' />
         <cms:no_results >
            Error: No Departments found!
         </cms:no_results>
      </cms:query>
      {
         "employee" :
         [
            <cms:pages masterpage='TDCouch3/dept-emp.php' folder=selected_folder>
            {
               "empDeptId"         :   "<cms:addslashes><cms:show k_page_folderid /></cms:addslashes>",
               "empId"               :   "<cms:addslashes><cms:show k_page_id /></cms:addslashes>",
               "empImage"         :   "<cms:addslashes><cms:show emp_image /></cms:addslashes>",
               "empName"            :   "<cms:addslashes><cms:show k_page_title /></cms:addslashes>",
               "empDept"            :   "<cms:addslashes><cms:show k_page_foldertitle /></cms:addslashes>",
               "empDesignation"   :   "<cms:addslashes><cms:show empdesignation /></cms:addslashes>",
               "empDoB"            :   "<cms:addslashes><cms:show emp_dob /></cms:addslashes>",
               "empDoA"            :   "<cms:addslashes><cms:show emp_doa /></cms:addslashes>",
               "ofcMob"            :   "<cms:addslashes><cms:show ofc_mob /></cms:addslashes>",
               "ofcLl"                  :   "<cms:addslashes><cms:show ofc_ll /></cms:addslashes>",
               "ofcExt"               :   "<cms:addslashes><cms:show ofc_ext /></cms:addslashes>",
               "ofcFax"               :   "<cms:addslashes><cms:show ofc_fax /></cms:addslashes>",
               "ofcEmail"            :   "<cms:addslashes><cms:show ofc_email /></cms:addslashes>",
               "ofcSite"               :   "<cms:addslashes><cms:show ofc_site /></cms:addslashes>",
               "ofcAddr"            :   "<cms:addslashes><cms:show ofc_addr /></cms:addslashes>",
               "persMob"            :   "<cms:addslashes><cms:show pers_mob /></cms:addslashes>",
               "persLl"               :   "<cms:addslashes><cms:show pers_ll /></cms:addslashes>",
               "persEmail"            :   "<cms:addslashes><cms:show pers_email /></cms:addslashes>",
               "persSite"            :   "<cms:addslashes><cms:show pers_site /></cms:addslashes>",
               "persAddr"            :   "<cms:addslashes><cms:show pers_addr /></cms:addslashes>"
            }
            <cms:if "<cms:not k_paginated_bottom />"> , </cms:if>
            </cms:pages>
         ]
      }
   </cms:if>
<?php COUCH::invoke(); ?>


This works fine. When ever I need to select all employees from a specific department, it outputs the same.

PROBLEM STATEMENT:
Develop a JSON that outputs only a specific employees' details. i.e., If i have reached a list of all employees in a specific department and want to now access a particular employees' FULL details, I want the JSON to output the same.

The current URL structure to find employees of a particular department is:
Code: Select all
http://www.sitename.com/json/employeeJSON.php?deptId=XX


I was wondering if something like:
Code: Select all
http://www.sitename.com/json/employeeJSON.php?deptId=XX&&empId=YY

could be done, or
Code: Select all
http://www.sitename.com/json/employeeJSON.php?empId=YY

could be done and how!

Please comment!
Image
where innovation meets technology
Hi,

You can use the code you posted to serve as a guide.
Supposing you chose the following URL -
Code: Select all
http://www.sitename.com/json/employeeJSON.php?empId=YY

Get the 'empid' querystring parameter and then use it as the value for 'id' parameter of <cms:pages> tag e.g. as follows -
Code: Select all
<cms:pages masterpage='TDCouch3/dept-emp.php' id=selected_id>
@KK Sir,
Thanks a ton... It works fine!!!
Image
where innovation meets technology
3 posts Page 1 of 1