Jump to content

Recommended Posts

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 } ?>

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321361
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321369
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321376
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321383
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-321407
Share on other sites

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 }} ?>

Link to comment
https://forums.phpfreaks.com/topic/64449-display-image/#findComment-322026
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.