Log in

View Full Version : warning help



boogyman
08-21-2007, 09:19 PM
I am getting this error

[21-Aug-2007 17:09:15] PHP Warning: Invalid argument supplied for foreach() in /path/Parts.php on line 168


Parts.php


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

djr33
08-21-2007, 09:23 PM
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).

boogyman
08-22-2007, 06:11 PM
Actually the $key is an array in itself, starting on the next line. but anyway that did it. Thanks