1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MySQL - getting a value from xf_user_field_value

Discussion in 'XenForo Development Discussions' started by Nnirvi, Mar 7, 2014.

  1. Nnirvi

    Nnirvi Member


    I'm trying to retrieve a value from the said table but when it comes to MySQL, I'm pretty clueless. The table has all the custom field values, I'm trying to get user ID based on a custom field (customernumber). So right now it's looking like this:

    $result_id = $db->fetchRow("SELECT COUNT(*) AS fetchid FROM xf_user_field_value WHERE field_value=" . $db->quote($customernumber) . " AND field_id='customernumber'");
    $fetched_id = $result_id[1];
    $customernumber is defined before the query.
  2. bill78

    bill78 Member

    Your SQL only counts the number of matches.

    Instead of:


    you need:

    SELECT user_id

    Secondly, the user_id would be stored in the array at position 0 (not 1), so:


    The other problem is that you need to query the database and then fetch the row, so it should be something like this:
    $sql = "SELECT user_id AS fetchid FROM xf_user_field_value WHERE field_value=" . $db->quote($customernumber) . " AND field_id='customernumber'";
    $query = $db->query($sql);
    $result_id = $db->fetchRow($query);
    $fetched_id = $result_id[0];
    Nnirvi likes this.
  3. Nnirvi

    Nnirvi Member


Share This Page