1

Racking my brain on why this is returning PHP Error: Undefined offset: 1

public function index($hash)
    {   
        //$hash = 44253_13456789
        list($part1,$part2) = explode('_', $hash);

        $id = $part1;

        $tpl_data = array('id' => $id );
        $this->load->view('main/index', $tpl_data);
    }

the error is happening on the list() = explode(); Thanks for any insight on this.

Here is the URL for the error. http://www.onlinealbumproofing.com/beta/ipad/index/44253_1368207168

UPDATED:

Here is the controller code.

echo $hash;

list($part1,$part2) = explode('_', $hash);

$id = $part1;

$tpl_data = array('id' => $id );
$this->load->view('ipad/index', $tpl_data);

Updated Again.... OK, so looks like the error is happening on the ajax request

var id = $('body').attr('id');

    $.ajax({
        url: 'ipad/loadImages',
        type: 'POST',
        dataType: 'json',
        data: {id: id},
        success: function(json, textStatus, xhr) {
            for (var i = 0; i < json.images.length; i++) {

                //do something
            }
        }, error: function(json, textStatus) {
            console.log(textStatus);
        }
    });
1
  • 1
    Are you 1000% sure the value of $hash is "44253_13456789"? Then this should not happen! Commented May 23, 2013 at 15:50

3 Answers 3

2

Your problem is explode() seems like to return only one value.

list() is trying to do :

 $tmp = explode("_", $hash);
 $part1 = $tmp[0];
 $part2 = $tmp[1]; //Here is your undefined offset.

Doublecheck your $hash value.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like the error is happening on the ajax request, not sure why the index function is even called again....
0

list($part1,$part2) requires the array has two elements at least.

If $hash doesn't has a _ in it, then explode('_', $hash) won't return an array with two elements.

1 Comment

That won't throw an offset error though, $part2 would simply be null
0

This is happening because you do not have 2 tokens being returned from your explode function. Which means you need to check the input to ensure that you will get the 2 tokens you require.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.