Images directed to different users?!?

Discussion in 'PHP' started by jmansa, Apr 28, 2008.

  1. #1
    I am trying to make a script where when I upload a image I can decide wich users who should be able to view this.

    The upload part is not the problem. It is uploadet into a db table with a multiple select box where I can choose wich users who should be able to view.

    The problem is when I want to retreive the data. The data is stored like this in my DB:
    id=15 uid=2,4,9,8,16,12 image=image.jpg

    This is how my script basicly looks like:
    require('dbconnect.php');
    
    if (($_GET['clubid']) && (is_numeric($_GET['clubid']))) {
    $club_id = $_GET['clubid'];
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die 
    ("Error connecting to mysql: " . mysql_error());
    
    mysql_select_db($dbname);
    
    $query="SELECT * FROM users WHERE club_id='".$club_id."'"; 
    $result=mysql_query($query) or die("Unable to find requested user");
    $currClub = mysql_fetch_array($result);
    
    $uid = is_numeric($currClub['uid']) ?  $currClub['uid'] : '';
    
    $result = mysql_query ("SELECT * FROM images WHERE uid IN (".$uid.")  ORDER BY RAND() LIMIT $num_displayed");
    
    while ($row = mysql_fetch_array($result)) 
    
    {
    $image = $row['image'];
    }
    
    echo ''.$image.'';
    
    } else {
    echo "No user specified";
    }
    PHP:
    Now, if my uid=2, I want to be able to look through the whole "images" table and find all the records where 2 is a part of the uid field.

    As it is now it doesnt get any??? Where am I going wrong. Please help!
     
    jmansa, Apr 28, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    rather use an extra table in your database to setup the link between users and the images

    example

    db_view
    user_id image_id
    1 2
    1 5
    1 9
    2 2
    2 4
    2 9
    etc etc
     
    EricBruggema, Apr 30, 2008 IP