proctk Posted July 22, 2007 Share Posted July 22, 2007 Hi I'm having a hard time with this section of code. for some reason its returning the blank image even when the child has an image. The blank image should only be shown if there was no image for the child. Thank you for any help spot where I think problem is <?php $arrayChild_id = array($child_id); foreach($arrayChild_id as $value): if($Imgchild_id == $value){ ?> <div style="paddin:2px;"><a href="profile.php?id=<?php echo $sibling_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> </div></td> <?php }else{ ?> <div><img src="user_images/blankAlbum.jpg" width="100" height="90" alt="blankAlbum.jpg" /></div> <? }//ends else endforeach;//end foreach endwhile;// ends while?> </tr> complete code $childQuery = "SELECT * FROM Links L, children C WHERE L.User_id = '$user_id' AND C.child_id = L.child_id"; $childResult=mysql_query($childQuery)or die("Childen Query Error: ".mysql_error()); while($childR=mysql_fetch_assoc($childResult)): $childfirstname = $childR['childfirstname']; $childlastname = $childR['childlastname']; $childdob = $childR['childdob']; $child_id = $childR['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 = '$user_id' AND album = 'Children'") or die("Can't Perform Query"); while($childImg=mysql_fetch_assoc($query_get_childImg)): $get_child_id = explode("-", $childImg['details']); $Imgchild_id = $get_child_id[2]; $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; ?> <table class="columntable" style="border:2px solid #EFF7C0;"> <tr> <td rowspan="4" style="width:30%;"> <?php $arrayChild_id = array($child_id); foreach($arrayChild_id as $value): if($Imgchild_id == $value){ ?> <div style="paddin:2px;"><a href="profile.php?id=<?php echo $sibling_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> </div></td> <?php }else{ ?> <div><img src="user_images/blankAlbum.jpg" width="100" height="90" alt="blankAlbum.jpg" /></div> <? }//ends else endforeach;//end foreach endwhile;// ends while?> </tr> <tr> <td colspan="2"><?php echo $childR['childfirstname'].' '.$childR['childlastname']; ?></td> </tr> <tr> <?php if(!empty($childR['childdob'])){ $child_age = birthday($childR['childdob']); } ?> <td><?php echo $childR['childdob']; ?></td> <td>Age:<?php echo $child_age; ?></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> <?php endwhile;?> Quote Link to comment Share on other sites More sharing options...
proctk Posted July 22, 2007 Author Share Posted July 22, 2007 The below update fixes the layout issues but it returning the same number or results for each child found. If there are three matches found then each child returns three results one is correct with the image and the other two show the blank image. This looks like a loop problem but I cannout figure out what the problem is any thoughts <?php $arrayChild_id = array($child_id); foreach($arrayChild_id as $value): if($Imgchild_id == $value){ ?> <tr> <td rowspan="4" style="width:30%;"> <a href="profile.php?id=<?php echo $sibling_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></td></tr> <?php }else{ ?> <tr> <td rowspan="4" style="width:30%;"> <img src="user_images/blankAlbum.jpg" width="100" height="90" alt="blankAlbum.jpg" /></td></tr> <? }//ends else endforeach;//end foreach ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted July 22, 2007 Share Posted July 22, 2007 Use code tags your code Quote Link to comment Share on other sites More sharing options...
proctk Posted July 22, 2007 Author Share Posted July 22, 2007 it has to do with the two while statements, help please Quote Link to comment Share on other sites More sharing options...
proctk Posted July 23, 2007 Author Share Posted July 23, 2007 This gets ride of the duplicate rows but id there is no photo then the code to display the blank image does not work <?php } if(empty($Imgchild_id)){ ?> <tr> <td rowspan="4" style="width:30%;"> <img src="user_images/blankAlbum.jpg" width="100" height="90" alt="blankAlbum.jpg" /></td></tr> <? } //ends else /*endforeach;*/ ///end foreach endwhile; ?> Quote Link to comment Share on other sites More sharing options...
proctk Posted July 26, 2007 Author Share Posted July 26, 2007 Since I first started this post I have worked out some big formating problems. however I'm still encountering a problem with displaying the blank image. I believe the snippet below is the problem. The logic is off and I don't know how to fix it. I'll try and explain. If there is an image then the image will displayed if there is no image then display the blank image. The common variable is the child_id which is in both mysql tables image_files and children. If the child_id is not found in the table image_files then the blank image needs to be displayed. any help is execellent problem area endforeach; $arrayImgchild_id = array($Imgchild_id); foreach($arrayImgchild_id as $value): if($child_id != $value){ ?> <img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /> updated code 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; ?> <?php $arrayImgchild_id = array($Imgchild_id); foreach($arrayImgchild_id as $value): if($child_id == $value){ ?> <?php 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 } } endforeach; $arrayImgchild_id = array($Imgchild_id); foreach($arrayImgchild_id as $value): if($child_id != $value){ ?> <img src="user_images/blankAlbum.jpg" width="75" height="75" alt="blankAlbum.jpg" /> <? } //ends else endforeach; ///end foreach endwhile; ?> </td> 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.