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. Link to comment https://forums.phpfreaks.com/topic/58179-solved-explode-troubles-or-maybe-foreach-trouble/ Share on other sites More sharing options...
bluebyyou Posted July 3, 2007 Author Share Posted July 3, 2007 Was that kind of unclear? Link to comment https://forums.phpfreaks.com/topic/58179-solved-explode-troubles-or-maybe-foreach-trouble/#findComment-288562 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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/58179-solved-explode-troubles-or-maybe-foreach-trouble/#findComment-288571 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? Link to comment https://forums.phpfreaks.com/topic/58179-solved-explode-troubles-or-maybe-foreach-trouble/#findComment-288585 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. Link to comment https://forums.phpfreaks.com/topic/58179-solved-explode-troubles-or-maybe-foreach-trouble/#findComment-288590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.