0

我有这个函数在调用它时返回三个值。

function GetCashierDetail ($UserID){

    $GetCashierID = "SELECT cashiers_CashierID,cashiers_Total,cashiers_Last_Total
                     FROM `cashiers`
                     WHERE `cashiers_CashierCloseDate` is null and `cashiers_Status`='0'
                     and `cashiers_Delete` = '0' and `cashiers_User` = '".$UserID."'";

    $objQueryCashierID = mysql_query($GetCashierID) or die ("Error Query [".$strSQL."]");
    $GetCashierIDResult = mysql_fetch_array($objQueryCashierID);
    $BillsCashierID = $GetCashierIDResult['cashiers_CashierID'];
    $CashierTotal = $GetCashierIDResult['cashiers_Total'];
    $CashierLastTotal = $GetCashierIDResult['cashiers_Last_Total'];
    $num = mysql_affected_rows();

    // Return Data
    return $cashier_data = array('cashierId'        => $BillsCashierID ,
                                 'CashierTotal'     => $CashierTotal ,
                                 'CashierLastTotal' => $CashierLastTotal);
}

现在调用这个函数时GetCashierDetail (11),我需要$cashier_data像这样打印 on 变量:

$ID = $BillsCashierID

以其他方式使用它。

我会尝试:

class Bills {

    // Get Cashier ID
    function GetCashierDetail ($ausers_ID){

        $GetCashierID = "SELECT cashiers_CashierID,cashiers_Total,cashiers_Last_Total
                         FROM `cashiers`
                         WHERE `cashiers_CashierCloseDate` is null and `cashiers_Status`='0'
                         and `cashiers_Delete` = '0' and `cashiers_User` = '".$UserID."'";
        $objQueryCashierID = mysql_query($GetCashierID) or die ("Error Query [".$strSQL."]");
        $GetCashierIDResult = mysql_fetch_array($objQueryCashierID);
        $BillsCashierID = $GetCashierIDResult['cashiers_CashierID'];
        $CashierTotal = $GetCashierIDResult['cashiers_Total'];
        $CashierLastTotal = $GetCashierIDResult['cashiers_Last_Total'];
        $num = mysql_affected_rows();
        // Return Data
        return $cashier_data = array('cashierId'        => $BillsCashierID ,
                                     'CashierTotal'     => $CashierTotal ,
                                     'CashierLastTotal' => $CashierLastTotal);
    }

}

$BillDraftSubmit = new Bills();
$data = $BillDraftSubmit->GetCashierDetail(71);
$cashierId = $data["cashierId"];
$CashierTotal = $data["CashierTotal"];
$CashierLastTotal = $data["CashierLastTotal"];
echo "cashierId" . $cashierId;
echo "<br>CashierTotal" . $CashierTotal;
echo "<br>CashierLastTotal" . $CashierLastTotal;

但我无法得到结果。

4

7 回答 7

2

怎么样:

$arr = GetCashierDetail (11);
extract($arr);
print $cashierId." ".$CashierTotal." ".$CashierLastTotal;
于 2013-03-01T20:18:56.570 回答
1
$return = GetCashierDetail(11);
$id = $return['cashierId'];

RTM: http: //php.net/manual/en/language.types.array.php

于 2013-03-01T20:18:10.143 回答
0

只需返回数组,无需将其分配给任何东西。IE

return array('cashierId'=>$BillsCashierID ,
                      'CashierTotal'=>$CashierTotal ,
                      'CashierLastTotal'=>$CashierLastTotal ); 

或者做

$cashier_data = array('cashierId'=>$BillsCashierID ,
                      'CashierTotal'=>$CashierTotal ,
                      'CashierLastTotal'=>$CashierLastTotal ); 
return $cashier_data;

然后当您将其归还时,$cd = GetCashierDetail(1);您可以访问$cd['CashierTotal']

于 2013-03-01T20:17:55.870 回答
0

为什么不只返回一个数组?

        function GetCashierDetail ($UserID){
    $GetCashierID = "SELECT cashiers_CashierID,cashiers_Total,cashiers_Last_Total 
    FROM `cashiers` 
    WHERE `cashiers_CashierCloseDate` is null and `cashiers_Status`='0' 
    and `cashiers_Delete` = '0' and `cashiers_User` = '".$UserID."'";
    $objQueryCashierID = mysql_query($GetCashierID) or die ("Error Query [".$strSQL."]");
    $GetCashierIDResult = mysql_fetch_array($objQueryCashierID);
    $BillsCashierID = $GetCashierIDResult['cashiers_CashierID'];
    $CashierTotal=$GetCashierIDResult['cashiers_Total']; 
    $CashierLastTotal=$GetCashierIDResult['cashiers_Last_Total']; 
    $num=mysql_affected_rows();
    // Return Data
    return array('cashierId'=>$BillsCashierID ,
                      'CashierTotal'=>$CashierTotal ,
                      'CashierLastTotal'=>$CashierLastTotal );                      

}  

$user = GetCashierDetail($id);
$ID = $user['cashierId'];
echo $ID;
于 2013-03-01T20:18:46.257 回答
0
//$UserID - your user's id
$result = GetCashierDetail ($UserID);
//now just using as normal array, for example
echo $result['cashierId'];
于 2013-03-01T20:18:52.407 回答
0

如果我正确理解了您的问题,您希望显示 Cashier ID 的值。

你可以这样做..

$cashierData = GetCashierDetail(11);

$ID = $cashierData['cashierId'];

echo 'cashier ID is: ' . $ID;

同样,您也可以通过$cashierData['CashierTotal']等获得 CashierTotal

于 2013-03-01T20:20:03.683 回答
0

我不确定我是否对你正确...

list($id,,) = GetCashierDetail(11);

echo $id;
于 2013-03-01T20:20:12.637 回答