Toby's solution still holds in this scenario.  Actually exactly has you have
rem'ed out.  You get back two components to the array, first array[0] holds
the concatenated string you made with the while loop and the second array[1]
holds the total number of result rows from your query.

Larry

-----Original Message-----
From: Dave Carrera [mailto:[EMAIL PROTECTED]
Sent: Sunday, January 18, 2004 6:11 AM
To: 'Toby Irmer'
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] Is this possible ?


Thanks Toby,

But I forgot to mention something that makes retuning an array not usable in
the context of my needs.

<?
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 in another function elsewhere.
        While($rows = mysql_fetch_array($sql){

    $returnsomething .="blah blah";
        }
     }
        return $returnsomething;
    // return array($returnsomething, $num); // your suggested answer
}

// list($text, $numrows) = MyFunc(); // Your suggested answer
?>

As you can see with my ammeded example I am already returning and array.

I thought I could cast the result $num into the $GLOBAL array for use later
but that dose not seem to work or be do able.

I could relicate the function and call it something else say MyFunc2() but
that seems a waste of code and mysql connection load when I am already
retrieving the var I want to use.

Any further ideas are appreciated.

Dave C

-----Original Message-----
From: Toby Irmer [mailto:[EMAIL PROTECTED]
Sent: 18 January 2004 10:29
To: Dave Carrera; [EMAIL PROTECTED]
Subject: Re: [PHP] Is this possible ?


One way:

<?
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 array($returnsomething, $num);
}

list($text, $numrows) = MyFunc();
?>

hth

toby

----- Original Message -----
From: "Dave Carrera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 18, 2004 11:22 AM
Subject: [PHP] Is this possible ?


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



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


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

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

Reply via email to