SQL for member database query

Discussion in 'Customization & add-ons' started by mlurie, Apr 5, 2008.

  1. mlurie

    mlurie New Member

    Joined:
    Dec 31, 2007
    Messages:
    14
    Hi,

    I am trying to pull the product id's of all products a user is subscribed to directly from the 'data' field of the member database.

    The following sql for a given member with $member_id:

    $sql = sprintf("SELECT data FROM amember_members WHERE member_id = %s",$member_id);

    gives me the following result:

    [data] => a:3:{s:6:"status";a:1:{i:1;i:1;}s:9:"is_active";i:1;s:17:"signup_email_sent";i:1;}

    What is the format of this string? What do the numbers represent? How do I figure out which product_ids the user is currently subscribed to?

    Thanks!

    Mark
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Here is what I can tell you about the string you provided:

    The data within the { after "status" indicates:

    a:1 - whether or not the user has any active products (1 active, 0 inactive)
    i1:1;i:1 - user has an active membership to product 1 (i:1<-product1;i:1<-active)

    This is the same data string you should see at the bottom of the user info screen for this user.

    On a side note, this works to get the products the user is subscribed to using data from session:

    Code:
    <?
    foreach ($_SESSION['_amember_products'] as $p){
    print "<a href='".$p['url']."'>".$p['title']."</a><br />";
    }
    ?>
    
  3. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    or

    Code:
    $_SESSION['amember_product_ids']
    if you just the product id (the above example gives product name hyperlinked to URL

Share This Page