Jump to content

Functions that return more than one value.


truegilly

Recommended Posts

Hi everybody,  :D

 

Simple one im sure...

 

i have a basic user defined function that returns values from a MySQL database using "mysql_fetch_row".

 

when i normally call a function that returns a single value i would simply assign the function to a variable and then echo it out.

 

$myFunc =  getNameOfSqdCdr();
echo $myFunc;

 

but lets say i have a function that returns 2 values, what is the syntax that defines which value is returned ?  ???

 

heres my code.... currently its just returning the $lastname variable.

 

function getNameOfSqdCdr() {

//perform query
$query = "SELECT Rank, Lastname FROM personnel WHERE job ='Squadron Commander'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// get a single row from the database
$row = mysql_fetch_row($result);

$rank = $row[0]; // value 1
$lastname = $row[1]; // value 2

return $lastname;

}

 

Any help is always much appreciated

 

Truegilly  :-*

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.