proctk Posted August 11, 2007 Share Posted August 11, 2007 This one has been giving me a hard time for a long while and I really need to help to get to the bottom of it. The goal is to display the users photo if one is found and if no photo is found then show the default "blankImage" if no image was found. The below displays both the blank image and the users image if an image is found. any help with this is greatly appreciated thank you //Gets buddies photo from the table images if one exists $query_get_photo = ("SELECT * FROM `image_files` WHERE `user_id` = '$buddy_id' AND `album` = 'Member'"); $get_photo = mysql_query($query_get_photo)or die("SQL Error: $query_get_photo <br>" . mysql_error()); while($photo = mysql_fetch_assoc($get_photo)){ $photoCount = mysql_num_rows($get_photo); ?> <?php if($photoCount > 0){ $image = "user_images/".$photo['image_name']; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; } ?> <img src="user_images/<?php echo $photo['image_name'];?>"width="<?php echo $newwidth; ?>" height="<?php echo $newheight?>" alt="<?php echo $photo['image_name'];?>" /> <?php } if(empty($photo['image_name'])){ ?> <a href="profile.php?id=<?php echo $buddy_id; ?>"><img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /></a><a href="profile.php?id=<?php echo $buddy_id; ?>"></a><?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/ Share on other sites More sharing options...
m1a2x3x7 Posted August 11, 2007 Share Posted August 11, 2007 ok 1 it you dont need two different if statements you can do a if else but ill let you run with this. instead of if(empty($photo['image_name'])){ try if($photoCount = 0){ Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321331 Share on other sites More sharing options...
proctk Posted August 11, 2007 Author Share Posted August 11, 2007 thanks for the post, I made the change and the same result occurs. If there is an image found then its displayed. If no image is found nothing is displayed. the image blank should display this one is confusing me Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321333 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 i echoed $photoCount and where the was an image found the number 1 is returned, where there is no image found nothing is returned. any ideas whats wrong Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321347 Share on other sites More sharing options...
Styles2304 Posted August 12, 2007 Share Posted August 12, 2007 I don't really know what I'm talking about here but is it possible that if there is no image that the $photocount is null as opposed to 0? Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321355 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 I tied empty and that did not work. that did not help. this should not be so hard. a simple if else should really do the trick :'( Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321358 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 I tried this and still the same issue the new part is this if (!empty($photo['image_name'])){ $imageName = $photo['image_name']; }else{ $imageName = 'blankAlbum.jpg'; } showing placement if($photoCount > 0){ $image = "user_images/".$photo['image_name']; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; if (!empty($photo['image_name'])){ $imageName = $photo['image_name']; }else{ $imageName = 'blankAlbum.jpg'; } Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321361 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 I have got the code down to this if there is no value for $photo['image_name'] then the blank image should be displayed if ($photo['image_name'] !=""){ $imageName = $photo['image_name']; $image = "user_images/".$imageName; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; } elseif($photo['image_name'] ==""){ $imageName = 'blankAlbum.jpg'; $newwidth=75; $newheight=100; } Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321369 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 I just figured out a huge problem. not every person will be found in the table image_files. I need to figure out how to change my if statememt so that if the buddy id was not found in the table then display the blank image. I have edited my code to this which is not working because the $photo['user_id'] != $buddy_id) statement does not work as $photo['user_id'] != $buddy_id) has no value. the bottom line is if the nothing is found in the query then I want the blank image to display any help is excellent if ($photo['user_id'] == $buddy_id){ $imageName = $photo['image_name']; $image = "user_images/".$imageName; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; } elseif($photo['user_id'] != $buddy_id){ $imageName = 'blankAlbum.jpg'; $newwidth=75; $newheight=100; } Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321376 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 alright the question is how do I compare the values in the variable $buddy_id to the values found from the query $photo['user_id']. A simple if should work but there will not alway bee the same number of value assigned to the two variables. Example $buddy_id was set for a while statement value [1] 2 value [2] 4 value [3] 5 $$photo['user_id'] value [1] = 2 Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321383 Share on other sites More sharing options...
proctk Posted August 12, 2007 Author Share Posted August 12, 2007 This will display the image but gives an error message for the spots where the blank image is supposed to display ERROR Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\familyclick\buddyList.php on line 120 any yet another approach to this while ($row = mysql_fetch_array($get_photo, MYSQL_ASSOC)) { $ids[] = $row['user_id']; $image_file[] = $row[image_name]; } foreach($ids as $value){ foreach ($image_file as $file){ if ($buddy_id == $value){ $imageName = $file; $image = "user_images/".$imageName; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; } if($buddy_id != $value){ $imageName = 'blankAlbum.jpg'; $newwidth=75; $newheight=100; } } } Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321407 Share on other sites More sharing options...
proctk Posted August 13, 2007 Author Share Posted August 13, 2007 Alright Its been days and I'm still banking my head on this one. The code should work but there is only one buddy_id showing when I echo $buddy_id within the while loop if I echo it outside the while loop all buddy Ideas show. I tried assigning the buddy Is to an array to bring them inside the while loop but its only returning the buddy ids that are found in the query help please I'm getting desperate $arrBuddy_id = array($buddy_id); //Gets buddies photo from thge table images if one exsists $query_get_photo = ("SELECT * FROM `image_files` WHERE `user_id` = '$buddy_id' AND `album` = 'Member'"); $get_photo = mysql_query($query_get_photo)or die("SQL Error: $query_get_photo <br>" . mysql_error()); while ($row = mysql_fetch_array($get_photo, MYSQL_ASSOC)) { print_r($arrBuddy_id); $countIds = mysql_num_rows($get_photo); if($buddy_id == $row['user_id']){ $image = "user_images/".$row['image_name']; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; ?> <a href="profile.php?id=<?php echo $buddy_id; ?>"><img src="user_images/<?php echo $row['image_name'] ;?>"width="<?php echo $newwidth; ?>" height="<?php echo $newheight?>" alt="<?php echo $row['image_name'];?>" /></a> <?php }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-322026 Share on other sites More sharing options...
proctk Posted August 13, 2007 Author Share Posted August 13, 2007 I was making this way to complicated I solved the issue Quote Link to comment https://forums.phpfreaks.com/topic/64449-display-image/#findComment-322032 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.