SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Separate

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Separate

    Hi all,

    I'm making a little buddy system and this is how i store buddies in the database:

    PHP Code:
    $buddy $_POST['buddy'];
    $user $_SESSION['username'];
    $data mysql_result(mysql_query("SELECT buddies FROM users WHERE username='$user'"), 0);

    if(
    $data == ""){
        
    mysql_query("UPDATE users SET buddies = '".$buddy."' WHERE username = '".$user."'") or die(mysql_error());
    }else{
        
    mysql_query("UPDATE users SET buddies = '".$data.",".$buddy."' WHERE username = '".$user."'") or die(mysql_error());

    No i want to list all the buddies from a user, but i don't know how to do it because i separated them with a comma.
    Hope someone can help with a little piece of code. Thank you

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could explode on the comma but i really really wouldn't use comma separated values in a database column, it leads to the darkside and a lot of pain later on. Your SQL will become cumbersome and you'll forever be battling against it. I'd have a separate table of buddies and a table to 'map' buddies to users.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •