2011-07-31 19 views
0

からの結果を反復処理する機能は、しかし、私が問題に実行している、非常に簡単になります。このように思える:、基本的にPHP:別の関数と出力

function getValidCustomers() { 
    global $db; 
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;"); 
    foreach($getCustomers as $customer) { 
     echo $customer['CustomerID']."\n"; 
    } 
} 

function updateValidCustomers() { 
    $customers = getValidCustomers(); 
    for ($i = 0; $i < sizeof($customers); $i++) { 
     echo "DEBUG: $customers[$i]\n"; 
    } 
} 

updateValidCustomers(); 

:ここ

コードです出力は今すぐ顧客IDのリスト(updateValidCustomers()から)です。 updateValidCustomers()からgetValidCustomers()のデータを取得してループして、実際にデータベースを操作する別のクエリを実行できるようにしたいだけです。

アイデア?

function getValidCustomers() { 
    global $db; 
    $getCustomers = $db->GetAll("SELECT * from customers where CustomerActive='1' AND protected IS NULL or protected=0;"); 
    foreach($getCustomers as $customer) { 
     echo $customer['CustomerID']."\n"; 
    } 
    return $getCustomers; 
} 

答えて

2

getValidCustomersは、多分あなたはこのことを意味し、何も返しませんgetValidCustomers()の末尾

+0

**一息**そう、近い。あなたは正しいです(他の人と一緒に)。私はもともと 'return $ customer ['CustomerID'];'を追加し、 'echo $ customer ['CustomerID']。\ n"; 'を置き換えましたが、それは基本的には一致した後に終了し、私の問題。先端の人に感謝します! – drewrockshard

1

getValidCustomers()return $getCustomers;を追加します: - それはちょうど

return $getCustomersへの追加をエコーD

2

getValidCustomers()は何も返さない

関連する問題