Sinikka Posted November 6, 2007 Share Posted November 6, 2007 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++; } Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 6, 2007 Share Posted November 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
Sinikka Posted November 6, 2007 Author Share Posted November 6, 2007 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++; } Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 6, 2007 Share Posted November 6, 2007 Sorry, I'm lost now... (not hard to do when I've been up for 20 hrs straight, mind you ) I'm out for the night... hopefully you'll get it sorted soon! PhREEEk Quote Link to comment Share on other sites More sharing options...
Sinikka Posted November 6, 2007 Author Share Posted November 6, 2007 Thanks for trying Basically all I did was add in the imaging code to the code that was already there but that made it to where it wouldn't show all the pets the owner had and it would show the one image, the name link went away as well. Quote Link to comment Share on other sites More sharing options...
Sinikka Posted November 6, 2007 Author Share Posted November 6, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
Sinikka Posted November 6, 2007 Author Share Posted November 6, 2007 bump Quote Link to comment Share on other sites More sharing options...
Sinikka Posted November 7, 2007 Author Share Posted November 7, 2007 bump 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.