2011-07-31 52 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()獲取數據,然後遍歷它,以便我可以在其上運行另一個實際上將操縱數據庫的查詢。

任何想法?

回答

2

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; 
} 
+0

**感嘆** - 如此密切。你是對的(和其他人一樣)。我最初添加了'return $ customer ['CustomerID'];'並且替換了'echo $ customer ['CustomerID']。「\ n」;',但是然後讀取它會在匹配後基本退出並且顯然沒有解析我的問題。感謝提示小夥! – drewrockshard

1

添加return $getCustomers;getValidCustomers():d

2

getValidCustomers()不返回任何東西 - 它只是相呼應

添加return $getCustomersgetValidCustomers()