Fatal error, PHP5 problem

Discussion in 'PHP' started by egdcltd, Feb 3, 2008.

  1. #1
    The following piece of code is now causing this error:

    
             $recipe_item = '<select name="recipe_item">';
             for( $i = 0; $i < count($item_list); $i++ )
             {
                $recipe_item[$i]['item_name'] = adr_get_lang($item_list[$i]['item_name']);
                $recipe_item .= '<option value = "'.$item_list[$i]['item_id'].'" >' . $item_list[$i]['item_name'] . '</option>';
             }
             $recipe_item .= '</select>'; 
    PHP:
    Now, I've read that PHP5 doesn't always handle this code the same way as PHP4, and that it's the $recipe_item[$i] bit that's causing problems, but I don't know how to fix it. Especially if there's a way to alter it so that it still works with PHP4.
     
    egdcltd, Feb 3, 2008 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    What is you are actually trying to do, because $recipe_item isnt an array :confused:
     
    papa_face, Feb 3, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    $recipe_item[$i]['item_name']
    Code (markup):
    Prior to that you're treating $recipe_item as a string. The error comes up because the above sniplet is trying to reference an index of an index.

    If $recipe_item[$i] was an array, then $recipe_item[$i]['item_name'] could exist.
    However, since $recipe_item is a string, $recipe_item[$i] is a single character, not an array.
     
    joebert, Feb 3, 2008 IP
  4. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The code is used to create a drop-down list. It works fine in PHP4, but some people have had problems with it in PHP5.
     
    egdcltd, Feb 4, 2008 IP
  5. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try change loop to this:
    for( $i = 0; $i < count($item_list); $i++ )
     {
    	$recipe_item .= '<option value = "'.$item_list[$i]['item_id'].'" >' . adr_get_lang($item_list[$i]['item_name']) . '</option>';
     }
    PHP:
     
    kreoton, Feb 4, 2008 IP
    egdcltd likes this.
  6. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks, that seems to have worked.
     
    egdcltd, Feb 4, 2008 IP