Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Has anyone been able to generate URL Queries to navigate through the JSON generated by couch?

Let's take this sample JSON response:
Is there a way to generate URL Queries like schedule_api.php?id=Monday to show only the results for the JSONObject Monday?

Code: Select all

   "schedule":{
      "day":[
         { 
            "id":"Monday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Tuesday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Wednesday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Thursday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Friday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Saturday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         },
         { 
            "id":"Sunday",
            "classes":[]
         }
      ]
   }
}
Hello, try something lijke this...
Code: Select all
$jsonDecode = json_decode($yourJson, true); //yourJson is a file or an URL

$day = getJson($jsonDecode);
$day = $day['day'];

echo $day['monday']['VAR']; ?>


Get the variable $day or something like this in your link

But i'm not a coder :)
When you're right and your girl say you're just mad...
Maybe this topic will help.
viewtopic.php?f=5&t=10892#p27841
trendoman wrote: Maybe this topic will help.
viewtopic.php?f=5&t=10892#p27841


Hello there! I am not quite sure how that translates into a URLQuerie...
So what exactly is what you need? Do you already have a working json-generating template?

A general tip for everyone who wants to get a quality help:
Kindly share with us a very detailed description of what you already have, how it works and what next step you are unsuccessfully trying to achieve. Attach sample working markup and codes. The help is on the way then.
trendoman wrote: So what exactly is what you need? Do you already have a working json-generating template?

A general tip for everyone who wants to get a quality help:
Kindly share with us a very detailed description of what you already have, how it works and what next step you are unsuccessfully trying to achieve. Attach sample working markup and codes. The help is on the way then.


I do have a working template:

Code: Select all
<cms:content_type 'application/json'/>

   "schedule":{
      "day":[
        <cms:set my_days_count='0' />
        <cms:pages masterpage='aerobic_schedule.php' order_by='id'> 
         { 
            "id":"<cms:show k_page_title />",
            "link"<cms:show k_page_link />",
            "classes":[
           
          <cms:set my_classes_count='0' />
            <cms:show_repeatable 'orar_aerobic' >
                {
                    "class" : "<cms:show curs />",
                    "time" : "<cms:show ora />:<cms:show minut />",
                    "trainer" : "<cms:show trainer />",
                    "canceled" : "<cms:if anulat=='DA'>Anulat</cms:if>"
                }
              <cms:incr my_classes_count />
              <cms:if my_classes_count!=k_total_records> , </cms:if>
           
            </cms:show_repeatable>
            ]
         }
        <cms:incr my_days_count />
        <cms:if my_days_count!=k_total_records> , </cms:if>
        </cms:pages>
      ]
   }
}


I want to get an idea on what I have to do in order to creare a url that queries the "id" key and displays results only for the selected value (e.g. schedule_api.php?id=Monday ) and the result should be only this:

Code: Select all

   "schedule":{
      "day":[
         { 
            "id":"Monday",
            "classes":[
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                },
                {
                    "class" : "Class",
                    "time" : "00:00",
                    "trainer" : "Teacher",
                    "canceled" : ""
                }
            ]
         }
      ]
   }
}
Thanks for explanation.
Put this to schedule_api.php

Code: Select all
<cms:set my_day = "<cms:gpc 'id' />" />


Then modify 'cms:pages' loop:

Code: Select all
<cms:pages masterpage='aerobic_schedule.php' order_by='id' page_title = my_day >  


If 'my_day' is empty in case no 'id' has been sent, then loop will ignore 'page_title' parameter as if it was not set.

Comma is handled with following (in part where there is 'my_days_count'):
Code: Select all
<cms:if k_paginated_bottom = '0'> , </cms:if>
YEAH!!! Thank you! This helped me a lot. Cheers!!!
8 posts Page 1 of 1

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests