Click to See Complete Forum and Search --> : display image


kproc
08-11-2007, 06:01 PM
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 } ?>

kproc
08-11-2007, 08:45 PM
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;
}

kproc
08-11-2007, 08:59 PM
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;
}

kproc
08-11-2007, 10:37 PM
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;
}
}
}

kproc
08-12-2007, 08:37 PM
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 }} ?>

kproc
08-12-2007, 08:45 PM
I was making this way to complicated I solved the issue