proctk Posted August 3, 2007 Share Posted August 3, 2007 Hi I'm trying to display an alternate image and its been giving me a problem ???. I'll try and explain If there is an image file found in the table image_files then i want it to be displayed and if there is no image found for that child then I want the blank image to display. If the child is a registered member then a link will be attached to the image and if the child is not a member then no link will be attached to the image. The below code displays the image if one is found but if no image is not found the blank image is not being displayed. I believe it has something to do with my if statements. ------------- if the child_id is found in the column familyMembers_id from the table image_files then there is an image for that child if the child_id is not found then there no image and the blank image should be displayed. ----- $query_get_children = "SELECT * FROM Links L, children C WHERE L.User_id = '$familyProfile_id' AND C.child_id = L.child_id"; $get_children=mysql_query($query_get_children)or die("Childen Query Error: ".mysql_error()); while($children=mysql_fetch_assoc($get_children)):?> <table class="table" style="width:80%"> <tr> <td rowspan="4" style="width:30%;"> <?php $childfirstname = $children['childfirstname']; $childlastname = $children['childlastname']; $childdob = $children['childdob']; $child_id = $children['child_id']; //Check If child is a registered user, if so offer link to view thier family profile if not display childs name only $child_check = mysql_query("SELECT * FROM users WHERE first_name ='$childfirstname' AND last_name='$childlastname' AND DOB = '$childdob'")or die(mysql_error()); $child_find = mysql_fetch_assoc($child_check); $childReg_id = $child_find['user_id']; //end $result check $query_get_childImg = mysql_query("SELECT * FROM image_files WHERE user_id = '$familyProfile_id' AND familyMember_id = '$child_id' AND album = 'Children'") or die("Can't Perform Query"); while($childImg=mysql_fetch_assoc($query_get_childImg)): $childCount=mysql_num_rows($query_get_childImg); if($childCount >0): $image = "user_images/".$childImg['image_name']; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; $newwidth=75; $newheight=($height/$width)*75; endif; /* $arrayImgchild_id = array($Imgchild_id); foreach($arrayImgchild_id as $value): if($child_id == $value){*/ if($child_id == $childImg['familyMember_id']){ if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /></a> <?Php }else{?> <img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /> <?php } } if($child_id != $childImg['familyMember_id']){ if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /></a> <?Php }else{?> <img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /> <? }} endwhile; ?> Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/ Share on other sites More sharing options...
cooldude832 Posted August 3, 2007 Share Posted August 3, 2007 can u show us just the part you are talking about Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314649 Share on other sites More sharing options...
teng84 Posted August 3, 2007 Share Posted August 3, 2007 your code is a mess can you clean that for us oops wait ill try to rewrite it but hmm i wish i dont get mad lol Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314651 Share on other sites More sharing options...
proctk Posted August 3, 2007 Author Share Posted August 3, 2007 Thank you for the help. Sorry about the mess. this is from my lack of training and having no idea what clean code looks like ???. here is the part I'm talking about thank you if($child_id == $childImg['familyMember_id']){ if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /></a> <?Php }else{?> <img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /> <?php } } if($child_id != $childImg['familyMember_id']){ if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /></a> <?Php }else{?> <img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /> <? }} Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314653 Share on other sites More sharing options...
cooldude832 Posted August 3, 2007 Share Posted August 3, 2007 few things stand out first if($child_id == $childImg['familyMember_id']){ $child_id is a blank value to start with (unless you array $childern is declared in a different place) secondly your elseif is a 100% reversal of your if therefore your else will never be reached be like say <?php $num = 1; if($num =1){ //yes } elseif($num != 1){ //no } else{ //I will never do this part because it will always be true in case A or B } ?> also you have a caps on your <?php in the else area Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314656 Share on other sites More sharing options...
seikan Posted August 3, 2007 Share Posted August 3, 2007 I think maybe JavaScript can help you in this case. <script language="JavaScript"> <!-- function showErrorImg(){ document.getElementById('mypic').src = "images/error.gif"; } //--> </script> <img src="<?php echo $childImg['image_name'];?>" id="mypic" onError="showErrorImg();"> Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314659 Share on other sites More sharing options...
proctk Posted August 3, 2007 Author Share Posted August 3, 2007 thank you for the posts, I thought that $child_id was set as an array because of this '$child_id = $children['child_id'];' Am I way out there. Thanks for the javascript post I don;t really follow that Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314661 Share on other sites More sharing options...
proctk Posted August 3, 2007 Author Share Posted August 3, 2007 my last post about the array was silly . The question the would be how Do i comapre the values from two arrays Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314663 Share on other sites More sharing options...
proctk Posted August 3, 2007 Author Share Posted August 3, 2007 Hi I'm trying this, does this make any sense. comparing the two arrays. The first part works where an image is found but the second part that is supposed to return a blank image is not working. any thoughts $foundImgs = array_intersect($arrchildImg, $arrchild_Id); foreach ($foundImgs as $key => $value) { /*if($child_id == $childImg['familyMember_id']){*/ if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /></a> <?Php }elseif(empty($childReg_id)){?> <img src="user_images/<?php echo $childImg['image_name'];?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /> <?php break; } } $notFoundImgs = array_diff($arrchildImg, $arrchild_Id); foreach ($notFoundImgs as $key => $value) { if(!empty($childReg_id)){ ?> <a href="profile.php?id=<?php echo $childReg_id; ?>"><img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" ?>" height="<?php echo $newheight; ?>" alt="<?php echo $childImg['image_name'];?>" /></a> <?Php }elseif(empty($childReg_id)){?> <img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /> <?php break; } } Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-314673 Share on other sites More sharing options...
proctk Posted August 3, 2007 Author Share Posted August 3, 2007 HI php Experts I'm having a hard time sorting through this challenge. I can get the images to display offering a link when needed. My problem is with displaying the blank image. help please .................. Quote Link to comment https://forums.phpfreaks.com/topic/63143-display-alternate-image-if-other-not-found/#findComment-315041 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.