Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 13th, 2004, 03:27 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default ImageLine Undefined offset error

I have a problem with my index. I have two arrays, one for the x coordinates $ld(), and one for the y coordiantes $la(). I want to draw lines betwween my points but I get an error message when ever I put in the $i+1 for the index of the second point.
Here's the code:

1400 for ($i = 0; $i < 1293; $i++) {
1401 ImageLine($im, $ld[$i], $la[$i], $ld[$i+1], $la[$i+1], $white);
1402 }

Here's the error:

<br />
<b>Notice</b>: Undefined offset: 1293 in <b>C:\Program Files\Abyss Web Server\htdocs\Test7.php</b> on line <b>1401</b><br />
<br />
<b>Notice</b>: Undefined offset: 1293 in <b>C:\Program Files\Abyss Web Server\htdocs\Test7.php</b> on line <b>1401</b><br />
‰PNG
IHDRXXÃpO PLTE (blah, blah, blah...)

What am I doing wrong?

Thanks!

  #2 (permalink)  
Old January 13th, 2004, 04:16 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well your program is complaining that that array indice doesn't exist.

Undefined offset will mean that a numeric based array indice isn't set at the time of use.

So echo the value of
echo $Id[$i];

Then look elsewhere in your script to be sure that $id[$i+1]; exists. If these are built using loops, does that loop iterate 1293 times?

If you need to detect whether a variable exists, or whether it contains a value look at isset and empty.

http://www.php.net/isset
http://www.php.net/empty

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
  #3 (permalink)  
Old January 13th, 2004, 04:22 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since you're only seeing the error once, I would guess that you're iterating your loop one too many times. If your last index is 1292, then the last *starting* point should be at index 1291, since that line's other endpoint is stored in index 1292.

Make sense?


Take care,

Nik
http://www.bigaction.org/
  #4 (permalink)  
Old January 13th, 2004, 04:37 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that's it exactly!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined Offset 7thsense101 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 December 9th, 2009 06:49 AM
Re: Undefined offset: 1 chapter 5 form.php sreenivasharish BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 9th, 2008 06:08 PM
undefined offset error trev Beginning PHP 9 January 24th, 2007 04:41 AM
Notice: Undefined offset: ## Herjan BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 27th, 2005 12:29 PM
Loops and Arrays - Undefined offset notice dkintheuk Beginning PHP 6 September 12th, 2005 11:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.