Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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!

Reply With Quote
  #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
:::::::::::::::::::::::::::::::::
Reply With Quote
  #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/
Reply With Quote
  #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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.