ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

create PHP array from channel entry results

April 13, 2011 6:38pm

Subscribe [3]
  • #1 / Apr 13, 2011 6:38pm

    adlur

    104 posts

    I can’t figure out why the following doesn’t work. Basically, I have two channels which contain member data as a VZ Member fields in Matrix cells or CKI Member List fields. The idea is to create an array of those member ids, compare it to the currently logged in user and, if there is a match, display data. The code is in an embedded template, the PHP is producing an array, everything checks out- but when I check the results by using in_array or in a foreach loop it never returns true.

    Thanks for looking!


    the currently logged in member, echoing this variable returns the correct value, the variable type is a string. Casting it as an integer returns 0 every time.

    $member = "{logged_in_member_id}";

    the array: when I print this array the values are correct. For what it’s worth, gettype shows all the values are strings, not integers.
    ex., Array ( [0] => 7 [1] => 54 [2] => 241 [3] => 1 [4] => 140 [5] => 35 [6] => 27 [7] => 215 [8] => 10 [9] => 239 [10] => 164 [11] => 224 [12] => 14 [13] => 157 [14] => 94 [15] => 239 [16] => 53 [17] => 83 [18] => 140 [19] => 190 [20] => 104 [21] => 164 [22] => 88 [23] => 121 [24] => 141 [25] => 26 [26] => 7 [27] => 137 [28] => 93 [29] => 10 [30] => 1 [31] => 218 [32] => 111 [33] => 91 [34] => 54 [35] => 5 )

    $execcomm = array(
    {exp:channel:entries channel="committee-membership_ch"}
    {com-chairs} 
    '{com-chairs_name}', 
    {/com-chairs}
    {/exp:channel:entries}
    {exp:channel:entries channel="executive-committee_ch"}
    {board}
    '{board_members}',
    {/board}
    '{president get="member_id"}','{vice-president get="member_id"}','{treasurer get="member_id"}','{rec-secretary get="member_id"}','{cor-secretary get="member_id"}','{past-president get="member_id"}',
    {/exp:channel:entries}
    );

    so either of these should work, there are definitely matches in the array, but it absolutely doesn’t. Is this a parse order problem? Is my php bad?

    foreach($execcomm as $value) {
        if($value == $member) { echo "match"; }
    }
    
    if(in_array($member, $execcomm)) { echo "match"; }
  • #2 / Apr 14, 2011 3:12pm

    Brandon Jones

    5500 posts

    Hi adlur,

    Moving this to the CodeShare Corner for you. Thanks.

  • #3 / Apr 14, 2011 9:12pm

    Dave @ Exp:resso

    465 posts

    Yip, think that’s a parse order problem. Make sure you’ve read and understand http://loweblog.com/downloads/ee-parse-order.pdf

    Echoing the string {logged_in_member_id} will work fine, because later on it will get converted to the actual value. Casting the string to int will return zero.

    Try this

    $member = $this->session->userdata['member_id'];
  • #4 / Apr 14, 2011 10:06pm

    adlur

    104 posts

    Bingo,

    $this->EE->session->userdata['member_id'];

    works like a charm.  Thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases