At 9:08 PM -0800 1/24/01, jeremy brand wrote:
>$array[0] will be the lang_pref and $array[1] will be the
>currency_pref.
>
>Jeremy


An easy way to read the returned array values into scalar variables is:

        list($lang_pref, $currency_pref) = PrefChange($language, 
$currency, $state);

You can only do this if your PrefChange function _always_ returns the 
same number of elements (two here; it could be any number). If you 
have a function that - for example - returns a 2-element array or 
FALSE if there's an error, then you have to do something a little 
more complex:

        $Stuff = PrefChange($language, $currency, $state);

        if (is_array($Stuff))
        {
#               ...do stuff with $Stuff !
        } else {
#               ...show error message
        }


- steve



>Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: [EMAIL PROTECTED]
>http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more
>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     "LINUX is obsolete"  -- Andy Tanenbaum, January 29th, 1992
>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>        http://www.JEEP-FOR-SALE.com/ -- I need a buyer
>   Get your own Free, Private email at http://www.smackdown.com/
>
>On Thu, 25 Jan 2001, Jamie wrote:
>
>>  Date: Thu, 25 Jan 2001 13:04:27 +0800
>>  From: Jamie <[EMAIL PROTECTED]>
>>  To: PHP <[EMAIL PROTECTED]>
>>  Subject: [PHP] multiple function returns
>>
>>  Can anyone help me I'm trying to read two results from a function by passing
>>  them out via an array but I'm not sure how to access them once I have done
>>  that. In the PHP manual it shows a list call which I can't seem to even find
>>  what the hell it does the code below runs without any errors but does not
>>  seem to work.
>>
>>  here the function gest passed the language and currency preference and a
>>  variable (1,0) to decide what it will do with them - update the preferences
>>  of the user or read out and define the preferences. (once updated I want it
>>  to read out the prefs aswell)
>>
>>  function PrefChange($lang,$curry,$state){
>>  global $DB_Server, $HTTP_Host, $DB_Login, $DB_Password, $DB_Name, $DocRoot ;
>>
>>  if ($state){//read preferences from page
>>    if (!($result = mysql_db_query($DB_Name,"SELECT language_pref,
>>  currency_pref FROM users WHERE user_id ='$cookie_user'"))){
>>     DisplayErrMessage(sprintf("internal error %s %s %s %d:%s\n",$DB_Server,
>>  $DB_Login, $DB_Password,
>>           mysql_errno(), mysql_error()));
>>     while ($row = mysql_fetch_array($results)){
>>           $lang_pref = $row["language_pref"];
>>           $currancy_pref = $row["currency_pref"];
>>      return array($lang_pref,$currancy_pref);
>>      }
>>     }
>>  } else {///update preferences from page
>>    if (!($result = mysql_db_query($DB_Name,"UPDATE users SET
>>  language_pref='$lang' AND currency_pref='$curry' WHERE
>>  user_id='$cookie_user'"))){
>>     DisplayErrMessage(sprintf("internal error %s %s %s %d:%s\n",$DB_Server,
>>  $DB_Login, $DB_Password,
>>           mysql_errno(), mysql_error()));
>>     PrefChange(0,0,1) ;
>>     }
>>  }
>>  }
>>
>>
>>  an example of what I'd like to do when calling the function (here I'm only
>>  reading the prefrences from the DB ), a select box that is showing the
>>  preference that is chosen with the preference read from the above function
>>  and the list created by the function below
>>
>>   <select name="form_lang_pref" style="font-family:verdana,
>>  Arial;font-size:8pt" CLASS:menu">
>>  <?
>>  list ($form_language_pref, $form_currency_pref) = PrefChange(0,0,1);
>>
>>            $select_id = $form_language_pref;
>>            $db = mysql_connect("$DB_Server", "$DB_Login, $DB_Password");
>>            mysql_select_db("$DB_Name",$db);
>>            $results = mysql_query("SELECT * FROM language ORDER BY language
>>  ",$db);
>>
>>            while ($row = mysql_fetch_array($results)){
>>                $rowid = $row["language_id"];
>>                $name = $row["language"];
>>                if ($rowid == $select_id) {
>  >                   echo("<option SELECTED value=\"$id\">$name</option>\n");
>>                } else {
>>                    echo("<option value=\"$id\">$name</option>\n");
>>                }
>>          //  endwhile;
>>        }
>>       echo("</select>");
>>  ?>
>  >
>


-- 
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to