Pulling member data from a database

Discussion in 'aMember Pro v.4' started by sstark, Nov 26, 2012.

  1. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    I need to be able to collect and then display member data. Previously I used session variables. Since v.4 and AM_Lite I cannot get this to work. This is the previous code that would allow users to see only their data. Can anyone help with this?

    Code:
    if (isset($_SESSION['_amember_id'])) {
      $colname_rsGoals = $_SESSION['_amember_id'];
    }
    mysql_select_db($database_connExercise, $connExercise);
    $query_rsGoals = sprintf("SELECT * FROM goals WHERE `_amember_id` = %s ORDER BY data_id DESC", GetSQLValueString($colname_rsGoals, "text"));
    $rsGoals = mysql_query($query_rsGoals, $connExercise) or die(mysql_error());
    $row_rsGoals = mysql_fetch_assoc($rsGoals);
    $totalRows_rsGoals = mysql_num_rows($rsGoals);
    
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is example which should work:
    PHP:
    $lite Am_Lite::getInstance();
    if(
    $lite->isLoggedIn()){
      
    $user $lite->getUser();
      
    $colname_rsGoals $user['user_id'];

    }
    mysql_select_db($database_connExercise$connExercise);
    $query_rsGoals sprintf("SELECT * FROM goals WHERE `_amember_id` = %s ORDER BY data_id DESC"GetSQLValueString($colname_rsGoals"text"));
    $rsGoals mysql_query($query_rsGoals$connExercise) or die(mysql_error());
    $row_rsGoals mysql_fetch_assoc($rsGoals);
    $totalRows_rsGoals mysql_num_rows($rsGoals);
  3. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    That works great, thanks!

    One other issue:
    I need to pull the user_id from the amember_user table. In the wiki, I don't see user_id. For instance I understand that the following will pull the username. Am_Lite::getInstance()->getUsername() I need the user_id. Is this possible. Do I have to modify the Lite.php file?

    Thank you.
  4. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    this will return you user_id:

    PHP:
    $lite Am_Lite::getInstance();
    if (
    $lite->isLoggedIn())
    {
        
    $user $lite->getUser();
        
    $user_id $user['user_id']; /// there is the id you are looking for
    }
  5. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    Alex -
    It's not working for me. What I need this for is to allow users to update their information. It's in a form as a hidden field and needs to be dropped into the data base in order to allow retrieval after being updated. Here's the exact code for the hidden field:
    Code:
    <input name="_amember_id" type="hidden" id="_amember_id" value="<?php $lite = Am_Lite::getInstance();
    if ($lite->isLoggedIn())
    {
        $user = $lite->getUser();
        $user_id = $user['user_id'];
    } 
    ?>" />
    I must be missing something? My database updates but in the _amember_id field is shows "Array" instead of the user_id.
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is correct code:
    PHP:
    <?php $lite Am_Lite::getInstance();
    if (
    $lite->isLoggedIn())
    {
        
    $user $lite->getUser();
        
    $user_id $user['user_id'];

    ?>
    <input name="_amember_id" type="hidden" id="_amember_id" value="<?php echo $user_id?>" />

Share This Page