Page 1 of 1

Using a function return value [SOLVED]

Posted: Tue Mar 18, 2008 8:56 am
by aceconcepts
Hi,

Forgive this lame post -

How do I use the return value from a function?

e.g.

Code: Select all

 
getClientDetails($clientSelectId);
 
$clientSelectedName=$clientDetailsResults['strClientName'];
 
function getClientDetails($clientId)
    {
        $clientDetails=mysql_query("SELECT * FROM tblClient WHERE intClientId='$clientId'");
        
        $clientDetailsResults=mysql_fetch_array($clientDetails);
        
        return $clientDetailsResults;
    }
So basically what I'm trying to do is get a value from a database using an id variable passed via the function paramaters.

I must be doing something wrond because when I output $clientSelectedName nothing is displayed!

Re: Using a function return value

Posted: Tue Mar 18, 2008 8:59 am
by Zoxive
aceconcepts wrote:Hi,

Forgive this lame post -

How do I use the return value from a function?

e.g.

Code: Select all

 
getClientDetails($clientSelectId);
 
$clientSelectedName=$clientDetailsResults['strClientName'];
 
function getClientDetails($clientId)
    {
        $clientDetails=mysql_query("SELECT * FROM tblClient WHERE intClientId='$clientId'");
        
        $clientDetailsResults=mysql_fetch_array($clientDetails);
        
        return $clientDetailsResults;
    }
So basically what I'm trying to do is get a value from a database using an id variable passed via the function paramaters.

I must be doing something wrond because when I output $clientSelectedName nothing is displayed!
The function is built correctly, but you are using it wrong.

Code: Select all

 
$Details = getClientDetails($clientSelectId);
 
$clientSelectedName=$Details['strClientName'];
 
The function returns the value of $clientDetailsResults, and needs somewhere to go.
In my example it is set to the Variable $Details.

Re: Using a function return value

Posted: Tue Mar 18, 2008 9:08 am
by aceconcepts
Nice one.