Good Evening,

I'm trying to modify a function that I wrote a few months ago to work on a 2 dimensional array instead of the single dimension I have been using.

My question is, before I start rewriting it only to find out that I can't do it...

Can you use array shift on a 2 dim array?

I'm dealing with a 3 by ___ array of members where each member can only have a maximum of 3 members directly related to their position.

The function that I currently use basically starts out by just doing a query to get the first 3 member ids, and pushes them into an array, then begins to walk that array using a while loop and an array shift, then checks for filled positions under each one of them and pushes those onto the array, then continues with the next iteration of the while loop.

It has been working just fine but now that we have had a member terminate their membership, the simple function is no longer effective, because at the point of the terminated member, it stops checking any positions under that position...

So, basically I need to use a 2 dim array to query for not only the mem_id, but also the status of the member, and count only the ones that are a status 'D', but still continue to process positions under all positions even if they aren't a status 'D'

Here is the function (actually 2 of them in combination) that I currently use that I need to modify for using a 2 dim array.

Any suggestions / cautions / directions would be greatly appreciated to save time in the trial and error phase of this.

// #########################################################
// start with any member ID and return total number of Active IRs in downline

function downline_count($under_mem) {
    // Determine number of Active downline members

    $down_ct = 0; // set counter
    $downline = downline_three($under_mem); // get initial array if one exists
    $element_ct = sizeof($downline); // should be from 0 - 3 elements in array
    if ($element_ct > 0){ // must be some downline on first level in matrix
      while (sizeof($downline) > 0){ // start walking array until it runs out
        ++ $down_ct;
        $under_mem = array_shift($downline);// remove and return first element
        $temp_array = downline_three($under_mem); // check for positions under it
        $downline = array_merge($downline, $temp_array);// merge elements with array
      }
      // when it drops out $down_ct should hold number in downline
    }
    return $down_ct;
 }


// #####################################################################
// start with any member and return the 3 positions under them in the matrix

function downline_three($by_three) {

    $down_elem = array(); // start with an empty array each time
    $sql = "
      SELECT mem_id
      FROM members
      WHERE up1_id = '".$by_three."'
      AND mem_status = 'D'
    ";

    if($result=mysql_query($sql)) {
      while ($filled=mysql_fetch_array($result)){
        $down_elem[] = $filled[0];
      }
    }
    return $down_elem; // return array with 0 to 3 elements
 }

Hi, can you show some example data and the table structure?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.