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 8534493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:12:35+00:00 2026-06-11T10:12:35+00:00

I have JSON Response Request and want make one variable $Where from them, this

  • 0

I have JSON Response Request and want make one variable $Where from them, this the JSON pattern :

"filter":
{"filters":[
    {"logic":"and","filters":[
        {"field":"NAMA","operator":"eq","value":"Rahmat"},
        {"field":"NAMA","operator":"eq","value":"Rosadi"}
    ]},{"logic":"or","filters":[
        {"field":"NIPK","operator":"eq","value":"1919191919"},
        {"field":"NIPK","operator":"eq","value":"818181818181"}
    ]},{"logic":"and","filters":[
        {"field":"JK","operator":"eq","value":"P"},
        {"field":"JK","operator":"eq","value":"L"}
    ]}
],
"logic":"and"}

Can anyone tell me how make thats patter to singgle row PHP variable like this :

$Where = "(NAMA = 'Rahmat' or NAMA = 'Rosadi') and (NIPK = '1919191919' or NIPK != '818181818181') and (JK='P' AND JK='L')"

Sorry for my bad english.

  • 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-11T10:12:36+00:00Added an answer on June 11, 2026 at 10:12 am

    You can enumerate the filters list into PHP arrays, building each of them as a list of SQL OR values, then join them with implode(' OR ', ...); and further implode the arrays in a list of ‘ AND ‘ clauses.

    This approach loses much of the flexibility allowed from your JSON setup, though; it can be extended to an AND-list of either OR-clauses or single clauses, and maybe coalesce OR clauses for the same field using the IN syntax, but not much more.

    You can look to algorithm that convert from RPN notation to algebraic to look for a more powerful (albeit more complex) approach.

    The simple version is

    $ops = array(
        'eq' => '=',
        'ne' => '!=',
        'gt' => '>',
        'lt' => '<',
        'ge' => '>=',
        'le' => '<=',
        // CHECK THIS OUT, FIX & COMPLETE
    );
    
    $arr_Filters = array();
    foreach($filters as $filter)
    {
        /* $filter is a set of subfilters:
           {"logic":"and","filters":[
              {"field":"NAMA","operator":"eq","value":"Rahmat"},
             {"field":"NAMA","operator":"eq","value":"Rosadi"}
           ]},
           which we see as:
        */
        $logic = $filter['logic'];
        $arr_Filter  = array();
        foreach($filter['filters'] as $fov)
        {
            $op_f = $fov['operator'];
            $op   = $ops[$op_f];
            $value = /* FUNCTION TO SQL ESCAPE A VALUE */ $fov['value'];
            $value = is_numeric($value) ? $value : "'".$value."'";
            $arr_Filter[] = "$fov[field] $op $value";
        }
        $arr_Filters[] = '('.implode(' ' . $filter['logic'] . ' ', $arr_Filter).')';
    }
    $sql_filter = 'WHERE ' . implode(' AND ', $arr_Filters);
    

    Using json_decode() an object can be retrieved that can be manipulated thus:

    // ($ops omitted, same as above)
    
    $arr_Filters = array();
    foreach($filters->filter->filters as $filter)
    {
        /* $filter is a set of subfilters:
           {"logic":"and","filters":[
              {"field":"NAMA","operator":"eq","value":"Rahmat"},
             {"field":"NAMA","operator":"eq","value":"Rosadi"}
           ]},
           which we see as:
        */
        $logic = $filter->logic;
        $arr_Filter  = array();
        foreach($filter->filters as $fov)
        {
            $op_f = $fov->operator;
            $op   = $ops[$op_f];
            $value = /* FUNCTION TO SQL ESCAPE A VALUE */ $fov->value;
            $value = is_numeric($value) ? $value : "'".$value."'";
            $arr_Filter[] = "{$fov->field} $op $value";
        }
        $arr_Filters[] = '('.implode(' ' . $filter->logic . ' ', $arr_Filter).')';
    }
    $sql_filter = 'WHERE ' . implode(' ' . $filters->filter->logic . ' ', $arr_Filters);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php function which returns JSON in response to a ajax request
I have a JSON response that is formatted from my C# WebMethod using the
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
If i have this json response {error:repeated} Why the alert is not showed? It
Basically, I have a JSON response from the Twitter API containing a timeline. I
I am getting a response from ajax request(done by jquery). I have a method
I have a json response like: { total: 2, success: true, rows: [ {a1_id:7847TK10,
We have a JSON response which can contain null values (e.g. { myValue: null
I'm developing an android app, and I need to have a json response of
I have the following JSON object: { response: { status: 200 }, messages: [

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.