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
https://forums.phpfreaks.com/topic/76166-solved-display-question/
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

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++;
}

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.