Jump to content

[SOLVED] Foreach Problem


proctk

Recommended Posts

Hi, I'm having a hard time with the foreach statement near the bottom of this code. I'm getting this error message

 

Warning: Invalid argument supplied for foreach() in

 

The code is searching for children that belongs to a user then gets the childs information from the table "Children'.  It then check to see if the child is a registered user in the table "users". Next it looks in the table "image_files" to see if the current user how is linked to the child has added a photo.  The photo can be identified by the child_id which matches the child_stored in at the end of the string stored in details.  Which is why I'm using explode

 

I tried an if statement but it returned the same photo for all children found. Note there was only one photo in the image_file data base.  I thought that I would ty a foreach loop as I know the child_id from both querys.  So if the child Id is not foun din the table image files then I want the file blank.jpg to show.  thank you for any help

$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'];
echo $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

$result = mysql_query("SELECT * FROM image_files WHERE user_id = '$user_id' AND album = 'Children'") or die("Can't Perform Query");

$get_child_id = explode("-", $childImg['details']);
$Imgchild_id = $get_child_id[2];
  

$childImg=mysql_fetch_array($result);

$childCount=mysql_num_rows($result);

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;

  ?>
<table class="columntable" style="border:2px solid #EFF7C0;">
  <tr>
  <?php foreach($child_id as $value){
  if($Imgchild_id == $value){
  
  ?>
    <td rowspan="4" style="width:30%;">  <div class="thumb" style="padding: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>
    <td><?php echo $childR['childfirstname'].' '.$childR['childlastname']; ?></td>
<?php 
}else{
?>
<td><img src="user_images/blankAlbum.jpg" width="125" height="100" alt="blankAlbum.jpg" /></td>
<? }}?>
  </tr>

Link to comment
https://forums.phpfreaks.com/topic/61242-solved-foreach-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.