Jump to content

[SOLVED] Display question


Sinikka

Recommended Posts

I'm trying to configure peoples profiles to show their pets as the image of the pet with the name as a link that takes you to the pet profile page. The problem I'm having is I can get the first pet to show but not any others and the name link that should display under the image will not show. Any help would be much appreciated.

 

$findPets = mysql_query("SELECT * FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'");
$numUserPets = mysql_num_rows($findPets);
$x = 0;
$image[$id] = "pet_$getPet[id]";
while ($getPets = mysql_fetch_array($findPets))

if ($getPets[wearing] != 0)
{
	$findLook = fetch("SELECT * FROM pet_looks WHERE change_from = '$getPets[species]' AND item_name = '$getPets[wearing]'");

	if ($findLook[id])
	{
		$image[$id] = "pet2_$findLook[id]";
	}
}

{
if ($x < $numUserPets)
{
	$petList .= "<img src=$base_url/images/user_images/opg_$game/pets/$image[$id].gif width=180 height= 180><br><a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a>";
}
else
{
	$petList .= "This user has no pets";
}
$x++;
}

Link to comment
Share on other sites

Your query is only going to return 0 or 1 pet, because you have the clause WHERE owner = '$members[id]' (and other conditions), which is very restrictive. It can only return 0 if no member id is found, or 1 record if the member id IS found.

 

You might need to rethink the logic if you want a larger number of owners returned.

 

PhREEEk

Link to comment
Share on other sites

Sorry the original coding had $x= 1; I set it to 0 to see if that made any difference and forgot to change it back. As well the original coding just showed a name link and it showed every pet the owner had. I'm not sure if this would help but here's the original with just the name link.

 

$findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'");
$numUserPets = mysql_num_rows($findPets);
$x = 1;
while ($getPets = mysql_fetch_array($findPets))
{
if ($x < $numUserPets)
{
	$petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), ";
}
else
{
	$petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])";
}
$x++;
}

Link to comment
Share on other sites

Ok, I got it to show the images and links correctly but now I can't for the life of me figure out how to get it to show like let's say 3 images per row.

 

$query = mysql_query("SELECT * FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = 

'$game'");
$query2 = mysql_query("SELECT * FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = 

'$game'");
$numQuery = mysql_num_rows($query2);


$x = 1;
while ($array = mysql_fetch_array($query2))
{
$id = $array[id];
$getPet = fetch("SELECT * FROM pets2 WHERE id = '$array[species]' AND game = '$game'");
$y = $x % 3;
if ($y == 0)
{
	echo "<tr>";
}

$image[$id] = "pet_$getPet[id]";

if ($array[wearing] != 0)
{
	$findLook = fetch("SELECT * FROM pet_looks WHERE change_from = '$array[species]' AND 

item_name = '$array[wearing]'");

	if ($findLook[id])
	{
		$image[$id] = "pet2_$findLook[id]";
	}
}

$petList .= "
<img src=$base_url/images/user_images/opg_$game/pets/$image[$id].gif width=100 height=100>
<br><a href=user_pets.php?game=$game&id=$array[id]&game=$game><b>$array[name]</b> the $getPet[name]!</a></p>";
if ($y == 3)
{
	echo "</tr>";
}
$x++;
}

if ($x == 0)
{
$petList .= "This user has no pets";
}

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.