Jump to content

Recommended Posts

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

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

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

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();">

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

 }

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.