/    Sign up×
Community /Pin to ProfileBookmark

how to send result of a mysql query into a function?

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..

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@dzysyakJun 20.2007 — [code=php]
my_function($result);
[/code]

Should work fine
Copy linkTweet thisAlerts:
@pcthugJun 20.2007 — [code=php]
function my_function($var)
{
mysql_fetch_assoc($var);
}

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

my_function($result);[/code]
Copy linkTweet thisAlerts:
@barantamerauthorJun 20.2007 — 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

[B][COLOR="Blue"]$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[/COLOR]
[/B]


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

[B][COLOR="Blue"]$result = mysql_query("select home_id,away_id from results");[/COLOR][/B]
×

Success!

Help @barantamer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...