Click to See Complete Forum and Search --> : how to send result of a mysql query into a function?


barantamer
06-19-2007, 11:13 AM
hello i would like to learn to send result of a mysql query into a function.
my mysql query is like this


$result = mysql_query("select home_id,away_id from results");


how can i used it in a function ,
i cant make it work like this

my_function(result);


btw ,i want to fetch my result in my function ..
help me please..

dzysyak
06-19-2007, 08:32 PM
my_function($result);

Should work fine

pcthug
06-19-2007, 09:30 PM
function my_function($var)
{
mysql_fetch_assoc($var);
}

$result = mysql_query("select home_id,away_id from results");

my_function($result);

barantamer
06-20-2007, 03:28 AM
Thank you for your answers , it woks fine,
However i have another question..:)

If i use the query result ($result) in a function it works fine for the first time
but in the second time it doesnt work..
as an example

$result = mysql_query("select home_id,away_id from results");

$number=my_function($result);
$number2=my_function($result)

echo $number; //prints 3
echo $number2; //prints 0 but the correct result is 3

so i would like to use the same query result in consecutive function calls,
is there anyway to do that without sending
this query again before i call the second function
$result = mysql_query("select home_id,away_id from results");