Results 1 to 3 of 3

Thread: warning help

  1. #1
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default warning help

    I am getting this error
    Code:
    [21-Aug-2007 17:09:15] PHP Warning:  Invalid argument supplied for foreach() in /path/Parts.php on line 168
    Parts.php
    Code:
    		if( $sqlHelper->execute() )
    		{
    			while( $sqlHelper->db->moveNext() )
    			{
    				$subArray[] = $sqlHelper->db->record;
    			}
    		}
    		
    		$key = $subArray['part_id'];
    		
    		if( $convertChars )
    		{
    line 168		foreach($subArray[$key] as $k => $val)
    			{
    				$subArray[$k] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
    			}
    		}
    please pardon sqlhelper... its part of the framework in the system to run the sql query
    any help?
    thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In almost all cases, that error comes up when the variable passed through the foreach loop is not an array.

    In this case, I believe you are for some reason using the $key index of the array instead of the array itself. It is possible that the $key index is an array in itself, but that doesn't appear to be the intent of your script.

    Use: foreach($subArray as $k => $val).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Actually the $key is an array in itself, starting on the next line. but anyway that did it. Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •