Field értékek kinyerése Views Results tömbből.

Szotyi képe

Sziasztok!

Tudtok segíteni abban, hogy hogyan kell kinyerni két mező - [field_1_sz_m], és [field_2_sz_m] - értékét Views Results tömbből?

Itt a Views táblázat:
1. szám, 2. szám
11, 14
6, 13

A feladatom az, hogy ezt a 4 számot egy kétdimenziós tömbbe visszakapjam, amivel majd mindenféle műveletet elvégzek.

A $result tömb kódja itt van, amit a print_r($results)-al kaptam meg. Kicsit hosszú - hogy minden benne legyen - , de formázva van.

Array ( 
  [0] => stdClass Object ( 
    [nid] => 6820 
    [node_nid] => 6820 
    [field_data_field_1_sz_m_node_entity_type] => node 
    [field_data_field_2_sz_m_node_entity_type] => node 
    [_field_data] => Array ( 
      [nid] => Array ( 
        [entity_type] => node 
        [entity] => stdClass Object ( 
          [vid] => 6820 
          [uid] => 1 
          [title] => 201347 
          [log] => Created by FeedsNodeProcessor 
          [status] => 1 
          [comment] => 1 
          [promote] => 0 
          [sticky] => 0 
          [nid] => 6820 
          [type] => _t_ssz_mok 
          [language] => und 
          [created] => 1386179811 
          [changed] => 1386179811 
          [tnid] => 0 
          [translate] => 0 
          [revision_timestamp] => 1386179811 
          [revision_uid] => 1
 
          [field_a_h_z_s_ve] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 2013
              ) 
            ) 
          )
 
          [field_a_h_z_s_hete] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 47
              )
            )
          )
 
          [field_a_h_z_s_d_tuma2] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 2013.11.23. 
                [format] => plain_text 
                [safe_value] => 2013.11.23. 
              ) 
            )
          )
 
          [field_5_tal_lat_db_] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 0
              )
            )
          )
 
          [field_5_s_nyerem_nye] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 0 Ft
                [format] => plain_text
                [safe_value] => 0 Ft
              )
            )
          )
 
          [field_4_tal_lat_db_] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 31
              )
            ) 
          )
 
          [field_4_es_nyerem_nye] => Array ( 
            [und] => Array (
              [0] => Array (
                [value] => 1 856 330 Ft 
                [format] => plain_text 
                [safe_value] => 1 856 330 Ft 
              ) 
            ) 
          )
 
          [field_3_tal_lat_db_] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 3089
              ) 
            ) 
          )
 
          [field_3_as_nyerem_nye] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 19 725 Ft
                [format] => plain_text
                [safe_value] => 19 725 Ft
              )
            )
          )
 
          [field_2_tal_lat_db_] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 91240
              ) 
            ) 
          )
 
          [field_2_es_nyerem_nye] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 1 300 Ft 
                [format] => plain_text 
                [safe_value] => 1 300 Ft 
              ) 
            ) 
          )
 
          [field_1_sz_m] => Array (
            [und] => Array (
              [0] => Array ( 
                [value] => 11
              )
            )
          )
 
          [field_2_sz_m] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 14
              )
            )
          )
 
          [field_3_sz_m] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 37
              )
            )
          )
 
          [field_4_sz_m] => Array (
            [und] => Array (
            [0] => Array (
              [value] => 57
              )
            )
          )
 
          [field_5_sz_m] => Array (
            [und] => Array (
              [0] => Array (
                [value] => 58
              )
            ) 
          )
 
          [field_1_es_db] => Array ()
 
          [rdf_mapping] => Array ( 
            [rdftype] => Array ( 
              [0] => sioc:Item [1] => foaf:Document 
            )
 
            [title] => Array ( 
              [predicates] => Array ( 
                [0] => dc:title
              )
            )
 
            [created] => Array (
              [predicates] => Array (
                [0] => dc:date 
                [1] => dc:created 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601 
            )
 
            [changed] => Array ( 
              [predicates] => Array ( 
                [0] => dc:modified 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601
            )
 
            [body] => Array ( 
              [predicates] => Array ( 
                [0] => content:encoded
              ) 
            )
 
            [uid] => Array ( 
              [predicates] => Array ( 
                [0] => sioc:has_creator 
              ) 
              [type] => rel
            ) 
 
            [name] => Array ( 
              [predicates] => Array ( 
                [0] => foaf:name 
              ) 
            )
 
            [comment_count] => Array ( 
              [predicates] => Array (
                [0] => sioc:num_replies
              )
              [datatype] => xsd:integer 
            ) 
 
            [last_activity] => Array ( 
              [predicates] => Array ( 
                [0] => sioc:last_activity_date 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601 
            )
          )
 
          [cid] => 0 
          [last_comment_timestamp] => 1386179811 
          [last_comment_name] => 
          [last_comment_uid] => 1 
          [comment_count] => 0 
          [name] => webmester 
          [picture] => 0 
          [data] => b:0; 
        ) 
      )  
    ) 
 
    [field_field_1_sz_m] => Array ( 
      [0] => Array ( 
        [rendered] => Array ( 
          [#markup] => 11 
          [#access] => 1
        ) 
        [raw] => Array ( 
          [value] => 11 
        )
      ) 
    ) 
    [field_field_2_sz_m] => Array (
      [0] => Array ( 
        [rendered] => Array ( 
          [#markup] => 14 
          [#access] => 1 
        ) 
        [raw] => Array ( 
          [value] => 14 
        )
      ) 
    ) 
  )
 
  //gondolom, hogy itt kezdődik a 2. sor. 
 
  [1] => stdClass Object (
    [nid] => 6821  
    [node_nid] => 6821 
    [field_data_field_1_sz_m_node_entity_type] => node 
    [field_data_field_2_sz_m_node_entity_type] => node 
    [_field_data] => Array (
      [nid] => Array (
        [entity_type] => node 
        [entity] => stdClass Object ( 
          [vid] => 6821 
          [uid] => 1 
          [title] => 201346 
          [log] => Created by FeedsNodeProcessor 
          [status] => 1 
          [comment] => 1 
          [promote] => 0 
          [sticky] => 0 
          [nid] => 6821 
          [type] => _t_ssz_mok 
          [language] => und 
          [created] => 1386179811 [changed] => 1386179811 
          [tnid] => 0 
          [translate] => 0 
          [revision_timestamp] => 1386179811 
          [revision_uid] => 1
 
          [field_a_h_z_s_ve] => Array ( 
            [und] => Array (
              [0] => Array ( 
                [value] => 2013 
              ) 
            ) 
          )
 
          [field_a_h_z_s_hete] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 46 
              ) 
            ) 
          )
 
          [field_a_h_z_s_d_tuma2] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 2013.11.16. 
                [format] => plain_text 
                [safe_value] => 2013.11.16. 
              ) 
            )
          ) 
          [field_5_tal_lat_db_] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 0 
              ) 
            ) 
          ) 
          [field_5_s_nyerem_nye] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 0 Ft 
                [format] => plain_text 
                [safe_value] => 0 Ft 
              ) 
            ) 
          ) 
          [field_4_tal_lat_db_] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 48 
              ) 
            ) 
          ) 
          [field_4_es_nyerem_nye] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 1 238 140 Ft 
                [format] => plain_text 
                [safe_value] => 1 238 140 Ft 
              ) 
            ) 
          ) 
          [field_3_tal_lat_db_] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 4295 
              ) 
            ) 
          ) 
          [field_3_as_nyerem_nye] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 14 650 Ft 
                [format] => plain_text 
                [safe_value] => 14 650 Ft 
              ) 
            ) 
          )
 
          [field_2_tal_lat_db_] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 110897 
              ) 
            ) 
          ) 
          [field_2_es_nyerem_nye] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 1 105 Ft 
                [format] => plain_text 
                [safe_value] => 1 105 Ft 
              ) 
            ) 
          ) 
          [field_1_sz_m] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 6 
              ) 
            ) 
          ) 
          [field_2_sz_m] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 13 
              ) 
            ) 
          ) 
          [field_3_sz_m] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 34 
              ) 
            ) 
          ) 
          [field_4_sz_m] => Array (
            [und] => Array ( 
              [0] => Array ( 
                [value] => 39 
              ) 
            ) 
          ) 
          [field_5_sz_m] => Array ( 
            [und] => Array ( 
              [0] => Array ( 
                [value] => 51 
              ) 
            ) 
          ) 
          [field_1_es_db] => Array ( ) 
          [rdf_mapping] => Array ( 
            [rdftype] => Array ( 
              [0] => sioc:Item 
              [1] => foaf:Document 
            ) 
            [title] => Array ( 
              [predicates] => Array ( 
                [0] => dc:title 
              ) 
            ) 
            [created] => Array ( 
              [predicates] => Array ( 
                [0] => dc:date 
                [1] => dc:created 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601 
            ) 
            [changed] => Array ( 
              [predicates] => Array ( 
                [0] => dc:modified 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601 
            ) 
            [body] => Array ( 
              [predicates] => Array ( 
                [0] => content:encoded 
              ) 
            ) 
            [uid] => Array ( 
              [predicates] => Array ( 
                [0] => sioc:has_creator 
              ) 
             [type] => rel 
            ) 
            [name] => Array ( 
            [predicates] => Array ( 
               [0] => foaf:name 
              ) 
            ) 
            [comment_count] => Array ( 
              [predicates] => Array ( 
                [0] => sioc:num_replies 
              ) 
              [datatype] => xsd:integer 
            )
 
            [last_activity] => Array ( 
              [predicates] => Array ( 
                [0] => sioc:last_activity_date 
              ) 
              [datatype] => xsd:dateTime 
              [callback] => date_iso8601 
            ) 
          ) 
          [cid] => 0 
          [last_comment_timestamp] => 1386179811 
          [last_comment_name] => 
          [last_comment_uid] => 1 
          [comment_count] => 0 
          [name] => webmester 
          [picture] => 0 
          [data] => b:0; 
        ) 
      ) 
    )
 
    [field_field_1_sz_m] => Array ( 
      [0] => Array ( 
        [rendered] => Array ( 
          [#markup] => 6 
          [#access] => 1 
        ) 
        [raw] => Array ( 
          [value] => 6 
        ) 
      ) 
    ) 
    [field_field_2_sz_m] => Array ( 
      [0] => Array ( 
        [rendered] => Array ( 
          [#markup] => 13 [#access] => 1 
        ) 
        [raw] => Array ( 
          [value] => 13 
        ) 
      ) 
    )
  ) 
)

Itt rögtön feljebb látszik is, hogy a
field_2_sz_m átváltozott field_field_2_sz_m -ra és az érték (13) is ott van, de hogy hogyan hivatkozhatok rá, azt nem tudom.

Persze az lenne a jó, ha a fenti táblázatot valahogy betölthetném egy kétdimenziós tömbbe.

Melyik modulhoz, modulokhoz kapcsolódik a téma?: 
Drupal verzió: 
Fórum: 
Szotyi képe

Megtaláltam, ime a kód:

$sorokszama = sizeof($results);
for ($i=0; $i<$sorokszama; $i++){
  $szam[$i][0]=$results[$i]->field_field_1_sz_m[0]['raw']['value'];
  $szam[$i][1]=$results[$i]->field_field_2_sz_m[0]['raw']['value'];
}

Bár elegánsabb lenne foreach függvénnyel, de arra nem tudtam rájönni.
Ez is működik. :)

0
0

Péter

kovarik képe

Szia,

Próbáld meg így:

  1. foreach($results as $result) {
  2. $szam[] = array(
  3. $result->_field_data["nid"]["entity"]->field_field_1_sz_m['und'][0]['value'],
  4. $result->_field_data["nid"]["entity"]->field_field_2_sz_m['und'][0]['value']
  5. );
  6. }
0
0