Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:59:33+00:00 2026-06-11T01:59:33+00:00

How to get rid of error: Undefined offset: 1 on line 20 ? I

  • 0

How to get rid of error: Undefined offset: 1 on line 20? I know it occurs becaouse Im calling array that’s offset simply does not exist.

Silecing it wiht @ just doesnt seem right at all.

//create an array with all x, y
for ($x = 1; $x <= 5; $x++) $array_x[] = $x;
for ($y = 1; $y <= 5; $y++) $array_y[] = $y;

$IN_x = "'" . implode("', '", $array_x) . "'";
$IN_y = "'" . implode("', '", $array_y) . "'";

$pullMapInfo = "SELECT x, y, value FROM mapinfo WHERE id='{$id}' AND x IN ({$IN_x}) AND y IN ({$IN_y})";
$pullMapInfo2 = mysql_query($pullMapInfo) or die('error here');

//create an associative array x, y => value
while ($pullMapInfo3 = mysql_fetch_assoc($pullMapInfo2)) {
    $result[ $pullMapInfo3['x'] ][ $pullMapInfo3['y'] ] = $pullMapInfo3['value'];
}

//loop to display output
foreach ($array_x as $x) {
foreach ($array_y as $y) {
    if (array_key_exists($x, $result) && array_key_exists($y, $result)) {
        echo '<div class="castle_array" id="'.$x,'x',$y.'">'. $result[$x][$y] .'</div>
                ';
    } else {
        echo '<div class="castle_array" id="'.$x,'x',$y.'"></div>
                ';
    }
}
}

2 for loops seems awkard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:59:35+00:00Added an answer on June 11, 2026 at 1:59 am

    Your second call to array_key_exists should pass in $result[$x]:

    if ( array_key_exists($x, $result) && array_key_exists($y, $result[$x]) ) {
        // Code goes here...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot figure out how to get rid of errors that should not be
How do i get rid of this error? code: function get_green_entities($c,$array){ $thisC = &$this->output[$this->sessID];
I have a pretty nasty error I can't get rid of. Here's the function
I'm trying to get rid of the save buttons on my websites. I know
Using adLDAP.php class receiving following error: Notice: Undefined index: memberof in /web/ee_web/include/adLDAP.php on line
How do I get rid of this error, I am using Visual Studio 2008
I'm looking for some help to get rid of this error. As i'm running
How do I get rid of the Notice: Undefined index: color in C:\xampp\htdocs\cpages\cmain\userfooter.php on
I get this JS error: jquery-1.5.1.min.js:16Uncaught TypeError: Cannot set property '_renderItem' of undefined d.d.extend._Deferred.f.resolveWithjquery-1.5.1.min.js:16
After downgrading* symfony-standard to 2.0.4 I get following error: Notice: Undefined index: locale in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.