Forum Moderators: coopster

Message Too Old, No Replies

mysql_fetch_array() problem

         

benj0323

5:56 pm on Jul 31, 2004 (gmt 0)

10+ Year Member



Basically what I want to do is take the entire array and apply the htmlentities function to each array element.

So here is what I am doing:

$result = $dbconn->query("select * from tablename");

while($case = fetch_array_html($result))

Here is the function:

function fetch_array_html($result)
{
$arr = mysql_fetch_array($result);
foreach($arr as $key=>$val)
{
$arr[$key] = htmlentities($val);
}
return $arr;
}

Here is the error I get:
Warning: Invalid argument supplied for foreach() on line 129

What exactly am I doing wrong here? I can usually fix my own errors, but this one is dominating me.

Any help is greatly appreciated. Thank you.

coopster

6:41 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are trying to process a result set that is already completely processed. You're logic should be changed accordingly. One way would be to process the mysql_fetch_array before running your function. Or, if you want to keep it as is, add an if statement.
function fetch_array_html($result) { 
if ($arr = mysql_fetch_array($result)) {
foreach($arr as $key=>$val) $arr[$key] = htmlentities($val);
return $arr;
}
}

benj0323

6:48 pm on Jul 31, 2004 (gmt 0)

10+ Year Member



Thanks a lot for the help. That worked perfect.