Using a function return value [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Using a function return value [SOLVED]

Post 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!
Last edited by aceconcepts on Tue Mar 18, 2008 9:08 am, edited 1 time in total.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Using a function return value

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Using a function return value

Post by aceconcepts »

Nice one.
Post Reply