bluebyyou Posted July 3, 2007 Share Posted July 3, 2007 I keep track of who is in a photo by storing the users id in the DB by comma separated values. Then I grab them back out with this: $tag = explode(",",$picturetag); foreach ($tag as $number) { if (in_array($number,$row)) { $query2 = "SELECT fname,lname FROM `member` WHERE `memberid` = $number"; query_db2($query2); $row2 = mysql_fetch_array($result2); echo "<a href='profile.php?id=$number'>$fname $lname ($number)</a><br />"; } } $picturetag is the column in the DB that stores the comma separated values So the problem I am having is that only two of my users are displayed. It will display the same user multiple times, but if it is a user other than the two they wont be shown. On this page http://www.wiuartinny.com/pic.php?id=38 you can see the "in this photo section. I have also echoed the entire picturetag field to show what users should be displayed. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 3, 2007 Author Share Posted July 3, 2007 Was that kind of unclear? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2007 Share Posted July 3, 2007 try <?php $query2 = "SELECT fname,lname,memberid FROM `member` WHERE `memberid` IN ($picturetag)"; $result2 = mysql_query($query2) or die (mysql_error()."<p>$sql</p>"); while (list($fname, $lname,$number) = mysql_fetch_row($result2)) { echo "<a href='profile.php?id=$number'>$fname $lname ($number)</a><br />"; } ?> Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 3, 2007 Author Share Posted July 3, 2007 Should I be doing that instead of everything I posted above? Do I still need the explode? Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 3, 2007 Author Share Posted July 3, 2007 Nevermind, I have never seen the IN operator used before. I used that exactly as you put it, and it solved the problem, thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.