Is it possible to return a loop? not the result but the loop it self. I want to create a function in php. For example like this.
function myloop($sql){
$quer
No, but you could do
function loopdate($sql,$code)
{
$query=mysql_query($sql)
while (mysql_fetch_assoc($query))
{
eval($code);
}
}
However - eval is rediculously dangerous its really really discouraged.
function loopdate($sql,$function)
{
$query=mysql_query($sql)
while ($data=mysql_fetch_assoc($query))
{
$function($data);
}
}
would be better.
myfunc($data)
{
foreach ($data as $key->$value)
{
print "".$key." ".$value." \n";
}
}
So you can call
loopdate("select * from mytable","myfunc");