Do this:
function MyFunc($num=NULL)
{
if(isset($_POST[var])){
 $sql = mysql_query("select * from table_name where field=\"$_POST[var]\"
");

 $num = mysql_num_rows($sql); // I want to use this result outside this
function.

$returnsomething ="blah blah";
 }
 return $returnsomething;
}

$numrows=0;
$res_arr=MyFunc(&$numrows);

Notice the &, that'll make the value of $numrows changed... I did not test
this at all, but it should work.. If you only do MyFunc(); without any
parameters, it'll just return the result of the SQL statement..
-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
"Dave Carrera" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
Hi List,

I have a function that makes a call to mysql based on certain vars.

---example----

Function MyFunc(){
 if(isset($_POST[var])){
 $sql = mysql_query("select * from table_name where field=\"$_POST[var]\"
");
 $returnsomething ="blah blah";
 }
 return $returnsomething;
}

And that all works fine no probs here but.....

I want to use a result somewhere in my script that is not returned by
return. Let me show you...

---example----

Function MyFunc(){
 if(isset($_POST[var])){
 $sql = mysql_query("select * from table_name where field=\"$_POST[var]\"
");

 $num = mysql_num_rows($sql); // I want to use this result outside this
function.

$returnsomething ="blah blah";
 }
 return $returnsomething;
}

So $num contains a number that I want to use outside the function which is
not covered by return.

I know return stops a script and returns what I want it to return but how do
I send out of the function the var I want.

I have tried $GLOBAL[var]=$num; but that don’t work, but I thought I
would'nt anyway just tried it and yes I know I have to declare it inside my
new function using global $var; to use it.

So I ask is this achiveable or how can I do this.

Thank you in advance

Dave C


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to