SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pulling and Displaying Multiple Interests...

    I've got http://www.rcmtv.tv/forma3.php form that captures info on users, at the bottom of the form there are several php-generated checkboxes. I had to use a join table to keep multiple interests selections.

    My tables:

    Users
    ID
    Name
    ...
    ...
    IID (interest ID)

    Interests
    ID
    Interest (the names)

    Join Table
    UID (User ID)
    IID

    Now my question: how do I pull the interests for each user? Then how do I display them separated by commas?Thanks.

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I'm a little confused...you only have one IID (interest ID) for each user but you allow them to have multiple interests?

    Suggested table design:

    Users
    UID
    Name
    ...

    Interests
    UID (corresponds to users.uid)
    Interest (full text)

    Then it would be a matter of putting it all together...

    PHP Code:
    $results mysql_query("SELECT * FROM user WHERE name='$name'");
    while (
    $user mysql_fetch_array($results) {
        
    $interests mysql_query("SELECT * FROM interests WHERE uid='$user[uid]'");
        
    $count mysql_num_rows($interests);
        
    $i=0;
        while (
    $interest mysql_fetch_array($interests)) {
            
    $i++;
            
    $interestlist .= $interest[interest];
            if (
    $i $count) {
                
    $interestlist .= ", ";
            }
        }
    }

    echo 
    "$name's Interests are: $interestlist"
    Note that if you are going to retreiving multiple users per page this would be very inefficient as it requires a query per user.
    Last edited by tubedogg; Aug 23, 2001 at 15:13.
    Kevin

  3. #3
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    And why would I want...

    a query per user? Isn't there another way of doing this?


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
  •