Jump to content

Undefined offset???


xavier.rayne

Recommended Posts

Hi, there ;)

 

Currently i'm doing on an assignment on how to create a photo album. I want to create a photo album that list the thumbnails below the big photo into 8 columns and 4 rows.

 

Below is my code for album.php:

<?php 
session_start();
include("../../config_pic.php");
?>
<script language="JavaScript">
var fadeimages=new Array()
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Untitled Document</title>
</head>

<body>
<?php require("rollover.php"); ?>
<TD class=content vAlign=top > <P class=Header> <?php echo "Welcome, " .$_SESSION['session_user']; ?></P>
		<p align="right"><a href="gallery.php">Back To Gallery</a></p>
            <table align="center" cellpadding="0" cellspacing="0">
              <tr><?php 
		  
			$SQL = "select name from images";
			$result = mysql_query($SQL);
			$row = mysql_fetch_array($result);
			$ProImg = $row; 

			$imgLoc1[]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg[$i]&w=400&h=400"; 
			?>
                <td colspan="8" height="400" width="400"><img id='psOne' height=400 src="<?php echo $imgLoc1[0]; ?>" width=400 border=0></td>
              </tr>

              
		  <?php 
		 $query2 = "SELECT * FROM images";
		 $result2 = mysql_query($query2);
		 $quantity = mysql_num_rows($result2);
		 $row2 = mysql_fetch_array($result2);
		 $ProImg2 = $row2;

		 for($i=0;$i<$quantity;$i++){
		 echo "<tr>";

			if($i%8 != 0){	  //if($i%8 != 0)
		 echo "ProImg2 is " . $ProImg2[$i];

		 $imgLoc2[$i]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";?> 
		  <td><A onmouseover=replaceImage($i);><IMG style="CURSOR: hand" height=50 alt="pink" src="<?php echo $imgLoc2[$i];  ?>" width=50 border="0"></A></td>
		  <? } //end if($i%8 != 0)
		  else { 
				echo "</tr>";
				} 
			}//end for loop
				?>
            </table>
		</tr>
</body>
</html>

 

When i run it at localhost, I always get the same error message:

Notice: Undefined offset: 2 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 2 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 3 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 3 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 4 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 4 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 5 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 5 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 6 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 6 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 7 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 7 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 9 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 9 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 10 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 10 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 11 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 11 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 12 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 12 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 13 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 13 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 14 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 14 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 15 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 15 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 17 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 17 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 18 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 18 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 19 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 19 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 20 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 20 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 21 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 21 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 22 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 22 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 23 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 23 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 25 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 25 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 26 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 26 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 27 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 27 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 28 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 28 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 29 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 29 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Notice: Undefined offset: 30 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 48

ProImg2 is

Notice: Undefined offset: 30 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\admin\album.php on line 50

 

Please....anyone here please help me to solve this problem :'(

 

Thanks..

 

EDITED BY WILDTEEN88: Please use code tag (


) when including code within posts.

Link to comment
Share on other sites

Undefined offset means that you're trying to access a part of an array that doesn't exist (it's in the for-loop you're doing this).

Use print_r() on $row2 to see if you're getting anything from the query. You should be, since the number of rows shows that you're getting something.

 

Also, use code tags!

Link to comment
Share on other sites

A mysql result consists of rows and columns.  For example

 

id  num

1  10

2  50

 

mysql_fetch_array() fetches one row only!  It's an "array" because each array element is one column.  So you must call mysql_fetch_array() many times, usually like this:

 

while ($row2 = mysql_fetch_arrow($result2)) {
  print "id: {$row2['id']}, num: {$row['num']}\n";
}

Link to comment
Share on other sites

I'm still facing with the offset problem:

 

The error message:

Notice: Undefined offset: 1 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 2 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 3 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 4 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 5 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 6 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

Notice: Undefined offset: 7 in C:\Program Files\Apache Group\Apache2\htdocs\photo_album\album.php on line 48

 

looping for 4 times.

 

Below is my edited code:

			 <?php 
		 //select images from table images(display all thumbnails for a category)
		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 if($result && mysql_num_rows($result) > 0)
		 {
			$i = 0;
			$max_columns = 8;
			while($row2 = mysql_fetch_array($result2)){
			//print_r($row2);
			$ProImg2 = $row2;
			//$ProImg2[] = $row2;

		  // open row if counter is zero
		  if($i == 0)
			 echo "<tr>";
			 $imgLoc2[]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";

		?> 

		  <td><A onmouseover=replaceImage($i);><IMG style="CURSOR: hand" height=50 alt="pink" src="<?php echo $imgLoc2[$i];  ?>" width=50 border="0" onClick="window.location.href='deleteimage.php?image=<?php echo $imgLoc2[$i]; ?>'"></A></td>
		  <?
		  // increment counter - if counter = max columns, reset counter and close row
		   if(++$i == $max_columns) 
		   {
			   echo "</tr>";
			   $i=0;
		   }  // end if(++$i == $max_columns) 
	   } // end while($row2 = mysql_fetch_array($result2)){
	} // end if results
	?>

Anyone, please help me..

Thanks

Link to comment
Share on other sites

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.