How to separate json with a mass relative to 2 fields



  • We don't need a base class. The use of the flames has never been good, the table is cosy. Dun mass. I'm forming it. php

    $row_section['cell'][$index] = array(
        0,
        $tovar,
        $cnt,
        $productID,
        $arElement["PROPERTIES"]["CML2_ARTICLE"]["VALUE"],
        $arElement["PROPERTIES"]["BREND"]["VALUE"],
        $arElement["NAME"],
        $n,
        $arElement["PROPERTIES"]["CML2_DAYS_DELIVERY"]["VALUE"],
        $price
    );
    $index=$index+1;
    

    $mas=json_encode($row_section,256);

    I'm sending a clip to the server on the table headline:

    <thead>
    <tr>
    <th class="def-table-code">
    <a href="<?=$url?>&sort=property_CML2_ARTICLE&method=<?=$method?>">Код</a>
    </th>

        &lt;th class="def-table-manufacturer"&gt;
            &lt;a href="&lt;?=$url?&gt;&amp;sort=property_BREND&amp;method=&lt;?=$method?&gt;"&gt;Производитель&lt;/a&gt;
        &lt;/th&gt;
    
        &lt;th class="def-table-title"&gt;
            &lt;a href="&lt;?=$url?&gt;&amp;sort=NAME&amp;method=&lt;?=$method?&gt;"&gt;Название&lt;/a&gt;
        &lt;/th&gt;
    
        &lt;!-- 
            &lt;th class="def-table-available"&gt;
                &lt;a href="&lt;?=$url?&gt;&amp;sort=CATALOG_QUANTITY&amp;method=&lt;?=$method?&gt;"&gt;Количество, шт.&lt;/a&gt;
            &lt;/th&gt;
    
            &lt;th class="def-table-delivery"&gt;
                &lt;a href="&lt;?=$url?&gt;&amp;sort=property_CML2_DAYS_DELIVERY&amp;method=&lt;?=$method?&gt;"&gt;Срок поставки, дн.
            &lt;/th&gt;
    
            &lt;th class="def-table-price"&gt;Цена, руб.&lt;/th&gt;
            &lt;th class="def-table-buy"&gt;В корзину&lt;/th&gt;
        --&gt;
    
        &lt;th class="def-table-available sort_id" id="CATALOG_QUANTITY" onclick="cat(5,1);"&gt;Количество, шт.&lt;/th&gt;
    
        &lt;th class="def-table-delivery sort_id" id="property_CML2_DAYS_DELIVERY" onclick="cat(6,1);"&gt;Срок поставки, дн.&lt;/th&gt;
    
        &lt;th class="def-table-price sort_id" id="CATALOG_PRICE" onclick="cat(7,1);"&gt;Цена, руб.&lt;/th&gt;
    
        &lt;th class="def-table-buy"&gt;В корзину&lt;/th&gt;
    &lt;/tr&gt;
    

    </thead>

    Sending. ajax Server request:

    function cat(sortby, method){
    alert(sortby);
    alert(method);
    $.ajax({
    url: '/unimann/ajax/sortfromcatalogajax.php?sortby='+sortby+'&method='+method
    type: 'POST',
    data: massiv,
    success: function(res) {
    $('#sort_tab').html(res);
    alert('Soxranenp!');
    }
    });
    }

    On the server, I:

    $data=  json_decode($_POST['massiv'],true);

    There'll be a mass (the server couldn't check, I don't know if it's gone).
    The idea should be that mass

    Array ( [cell] => Array ( [0] => Array ( [0] => 1 [1] => 453852 [2] => TB215363 [3] => FENOX [4] => TB215363_диск тормозной передний!\ Audi 80/90/100 1.6-2.0D 86-91 [5] => 6 [6] => 1 [7] => 772.52 ) [1] => Array ( [0] => 1 [1] => 355471 [2] => 8DD 355 100-581 [3] => HELLA [4] => Диск тормозной AUDI 80 86>91/100 76>88 передний не вент. [5] => 2 [6] => 1 [7] => 1044.41 ) [2] => Array ( [0] => 1 [1] => 228617 [2] => 0986478016 [3] => BOSCH [4] => Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 6 [6] => 1 [7] => 1126.23 ) [3] => Array ( [0] => 1 [1] => 440468 [2] => 0986478016 [3] => BOSCH [4] => Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 2 [6] => 1 [7] => 1126.23 ) [4] => Array ( [0] => 1 [1] => 228618 [2] => 0986478016 [3] => BOSCH [4] => Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 2 [6] => 1 [7] => 1126.23 ) [5] => Array ( [0] => 1 [1] => 140741 [2] => BG2215 [3] => DELPHI [4] => Диск тормозной AUDI 80 86>91/100 76>88 передний не вент. [5] => 2 [6] => 1 [7] => 876.12 ) [6] => Array ( [0] => 1 [1] => 128269 [2] => A1081P [3] => LPR [4] => Диск тормозной AUDI 80 86>91/100 76>88 передний не вент. [5] => 2 [6] => 1 [7] => 1046.65 ) [7] => Array ( [0] => 1 [1] => 184737 [2] => 24.0113-0160.1 [3] => ATE [4] => Диск тормозной передн, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo [5] => 4 [6] => 2 [7] => 1216.57 ) [8] => Array ( [0] => 1 [1] => 315459 [2] => 24.0113-0160.1 [3] => ATE [4] => Диск тормозной передн, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo [5] => 10 [6] => 1 [7] => 1216.57 ) ) )

    Question: How to divide or pole cell[][5]or cell[][6]or cell[][7] concerning cell[][0] and cell[][1]? I mean, we compare the elements that have cell[][1] It's the same, and it's sorted by growing or losing.

    We need to quarry within the unit. In the panel:
    введите сюда описание изображения



  • There's a function, http://php.net/manual/ru/function.array-multisort.php

    $babbie = Array ( "cell" => Array ( 
            "0" =>  Array ( 
                "0" => 1,
                "1" => 453852, 
                "2" => "TB215363", 
                "3" => "FENOX",
                "4" => "TB215363_диск тормозной передний!\ Audi 80/90/100 1.6-2.0D 86-91",
                "5" => 6,
                "6" => 1,
                "7" => 772.52), 
            "1" => Array ( 
                "0" => 1,
                "1" => 355471, 
                "2" => "DD 355 100-581", 
                "3" => "HELLA",
                "4" => "Диск тормозной AUDI 80 86>91/100 76>88 передний не вент.",
                "5" => 2, 
                "6" => 1,
                "7" => 1044.41 ), 
            "2" => Array ( 
                "0" => 1,
                "1" => 228617,
                "2" => "0986478016", 
                "3" => "BOSCH",
                "4" => "Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.",
                "5" => 6,
                "6" => 1,
                "7" => 1126.23 ), 
            "3" => Array ( 
                "0" => 1,
                "1" => 440468, 
                "2" => "0986478016", 
                "3" => "BOSCH", 
                "4" => "Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.",
                "5" => 2,
                "6" => 1,
                "7" => 1126.23 ), 
            "4" => Array ( 
                "0" => 1,
                "1" => 228618, 
                "2" => "0986478016", 
                "3" => "BOSCH",
                "4" => "Диск тормозной передн AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.",
                "5" => 2,
                "6" => 1,
                "7" => 1126.23 ), 
            "5" => Array ( 
                "0" => 1,
                "1" => 140741, 
                "2" => "BG2215",
                "3" => "DELPHI",
                "4" => "Диск тормозной AUDI 80 86>91/100 76>88 передний не вент.", 
                "5" => 2,
                "6" => 1,
                "7" => 876.12 ), 
            "6" => Array ( 
                "0" => 1,
                "1" => 128269,
                "2" => "A1081P",
                "3" => "LPR",
                "4" => "Диск тормозной AUDI 80 86>91/100 76>88 передний не вент.",
                "5" => 2,
                "6" => 1,
                "7" => 1046.65 ), 
            "7" => Array ( 
                "0" => 1,
                "1" => 184737,
                "2" => "24.0113-0160.1",
                "3" => "ATE",
                "4" => "Диск тормозной передн, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo",
                "5" => 4,
                "6" => 2,
                "7" => 1216.57 ), 
            "8" => Array ( 
                "0" => 1,
                "1" => 315459,
                "2" => "24.0113-0160.1", 
                "3" => "ATE",
                "4" => "Диск тормозной передн, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo",
                "5" => 10,
                "6" => 1,
                "7" => 1216.57 ) ) );
    

    print("<pre>"); print_r($babbie); print("</pre>");
    // Получение списка столбцов массива $babie["cell"]
    foreach ($babbie["cell"] as $key => $row) {
    $col_0[$key] = $row[0];
    $col_1[$key] = $row[1];
    }
    // Сортируем данные по col_0 по col_1 по возрастанию
    // Добавляем $babbie["cell"] в качестве последнего параметра, для сортировки по общему ключу
    array_multisort($col_0, SORT_ASC, $col_1, SORT_ASC, $babbie["cell"]);
    print("<pre>"); print_r($babbie); print("</pre>");

    Results:

    Array
    (sighs)
    [cell] = constitutional Array
    (sighs)
    [0] = constituent Array
    (sighs)
    [0] = section 1
    [1] = sector 453852
    [2] = sector TB215363
    [3] = sector FENOX
    _
    [5] = section 6
    [6] = section 1
    [7] = sector 772.52
    )

    [1] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 355471
    [2] =osphere DD 355 100-581
    [3] = station HELLA
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] =state 1044.41
    )

    [2] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 228617
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 6
    [6] = section 1
    [7] = sector 1126.23
    )

    [3] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 440468
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 2
    [6] = section 1
    [7] = sector 1126.23
    )

    [4] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 228618
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 2
    [6] = section 1
    [7] = sector 1126.23
    )

    [5] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 140741
    [2] = sector BG2215
    [3] = DC DELPHI
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] = section 876.12
    )

    [6] = constituent Array
    (sighs)
    [0] = section 1
    [1] = majority 128269
    [2] = section A1081P
    [3] = constituent LPR
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] =state 1046.65
    )

    [7] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 184737
    [2] = Article 24.0113-0160.1
    [3] = condition
    [4] = Bottomk Disk, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo
    [5] = majority 4
    [6] = section 2
    [7] = sector 1216.57
    )

    [8] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 315459
    [2] = Article 24.0113-0160.1
    [3] = condition
    [4] = Bottomk Disk, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo
    [5] = section 10
    [6] = section 1
    [7] = sector 1216.57
    )

    )

    )
    Array
    (sighs)
    [cell] = constitutional Array
    (sighs)
    [0] = constituent Array
    (sighs)
    [0] = section 1
    [1] = majority 128269
    [2] = section A1081P
    [3] = constituent LPR
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] =state 1046.65
    )

    [1] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 140741
    [2] = sector BG2215
    [3] = DC DELPHI
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] = section 876.12
    )

    [2] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 184737
    [2] = Article 24.0113-0160.1
    [3] = condition
    [4] = Bottomk Disk, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo
    [5] = majority 4
    [6] = section 2
    [7] = sector 1216.57
    )

    [3] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 228617
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 6
    [6] = section 1
    [7] = sector 1126.23
    )

    [4] = sector Array
    (sighs)
    [0] = section 1
    [1] = sector 228618
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 2
    [6] = section 1
    [7] = sector 1126.23
    )

    [5] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 315459
    [2] = Article 24.0113-0160.1
    [3] = condition
    [4] = Bottomk Disk, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo
    [5] = section 10
    [6] = section 1
    [7] = sector 1216.57
    )

    [6] = constituent Array
    (sighs)
    [0] = section 1
    [1] = sector 355471
    [2] =osphere DD 355 100-581
    [3] = station HELLA
    [4] = AUDI 80 86 section91/100 76 constant88 front not.
    [5] = section 2
    [6] = section 1
    [7] =state 1044.41
    )

    [7] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 440468
    [2] = 0586478016
    [3] = sector BOSCH
    [4] = AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1.
    [5] = section 2
    [6] = section 1
    [7] = sector 1126.23
    )

    [8] = Ter Array
    (sighs)
    [0] = section 1
    [1] = sector 453852
    [2] = sector TB215363
    [3] = sector FENOX
    _
    [5] = section 6
    [6] = section 1
    [7] = sector 772.52
    )

    )

    )

    Keep reading the documentation.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2