Issue with MySQL

Discussion in 'PHP' started by chuckd1356, Feb 8, 2008.

  1. #1
    So I have a table that looks like this...
    CREATE TABLE users (
    blah blah blah
    friends text NOT NULL,
    blah
    );

    and in `friends` is data like this: '1,868,28,5895,23,239'
    All of the numbers correspond to another members UID.

    I'm trying to select just the friends out of the table, so it's efficient and fast. That's easy. One simple query that looks like this:
    $sel_friends = mysql_query("SELECT friends FROM users WHERE uid='$somevar'")...
    PHP:
    But I can't seem to find a way to get that data into one variable that's not an array.

    So what I want to do, is get a $var to come back so if I print it, I see this:
    '1,868,28,5895,23,239'

    Thats it. I can handle everything else. I just can't seem to find a way to get that into a single variable without using loops and all that nonsense.

    Thanks.
     
    chuckd1356, Feb 8, 2008 IP
  2. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You just want to be able to retrieve the value of the friends field for a specific user?
     
    The Critic, Feb 8, 2008 IP
  3. chuckd1356

    chuckd1356 Active Member

    Messages:
    770
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Yes. That's all.
    No array, no loops, just one variable.
    How?
     
    chuckd1356, Feb 8, 2008 IP
  4. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    $sel_friends = mysql_query("SELECT friends FROM users WHERE uid='$somevar'");
    $var=@mysql_result($sel_friends,0);
    //Outputs '1,868,28,5895,23,239'
    echo $var;
    
    PHP:
    EDIT: I know I said mysql_fetch_row would be better/faster, but I doubt you'll see a difference on only one field from one row.
     
    The Critic, Feb 8, 2008 IP
  5. chuckd1356

    chuckd1356 Active Member

    Messages:
    770
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    70
    #5
    sweet, thanks.
     
    chuckd1356, Feb 8, 2008 IP
  6. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Happy to help. :)
     
    The Critic, Feb 8, 2008 IP