truegilly Posted February 8, 2007 Share Posted February 8, 2007 Hi everybody, 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 Link to comment https://forums.phpfreaks.com/topic/37653-functions-that-return-more-than-one-value/ Share on other sites More sharing options...
ShogunWarrior Posted February 8, 2007 Share Posted February 8, 2007 Return an array like so: return array($rank,$lastname); And when you call the function: $myFunc = getNameOfSqdCdr(); $rank = $myFunc[0]; $lastname = $myFunc[1]; Link to comment https://forums.phpfreaks.com/topic/37653-functions-that-return-more-than-one-value/#findComment-180122 Share on other sites More sharing options...
truegilly Posted February 8, 2007 Author Share Posted February 8, 2007 ah, very clever !! Thanks !! Link to comment https://forums.phpfreaks.com/topic/37653-functions-that-return-more-than-one-value/#findComment-180135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.