I have a question regarding applying a custom function to mysql_fetch_assoc while it is in the while loop. See code below.
//current php page
$query = mysql_query("SELECT ... "); //returns multiple rows
while($rs = whileF($query)) {
//do some fantastic stuff
}
//... functions.php page
function whileF($value = array()) {
$var = mysql_fetch_assoc($value);
foreach($var AS $k => $v) {
$var[$k] = stripslashes($v);
}
return $var;
}
My question is I'd like to be able to automatically strip the slashes our of the different fields with this type of a function (and I'd also like to record some debug data if necessary), but it doesn't seem to cooperate too well. If I do a..
print_r($var);
it will return all the values in an array, but by doing the foreach statement I keep getting "Warning: Invalid argument supplied for foreach() in /home/.../includes/functions.php" and if I try this...
$var = array_map('stripslashes',$var);
I get "Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/.../includes/functions.php"
The odd part is, it seems like it applies the foreach/array_map functions properly (the values are being stripped). I don't want to turn off errors, just to make them go away as that would be......less effective programming. I know that the whileF() function works properly cause it's still displaying all the info and if I take away the foreach/array_map statements it'll run without any errors.
Thoughts? I know I'm missing something......
Thanks in advance.