Jump to content

[SOLVED] explode() troubles or maybe foreach trouble


bluebyyou

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.