看起来这很简单,但是,我遇到了一个问题:
以下是代码:
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();
基本上,现在的输出是CustomerID的列表(来自updateValidCustomers()
)。我只是希望updateValidCustomers()
从getValidCustomers()
获取数据,然后循环遍历它,这样我就可以在其上运行另一个实际操作数据库的查询。
有什么想法吗?
答案 0 :(得分: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;
}
答案 1 :(得分:2)
getValidCustomers()
不返回任何内容 - 它只是回显
将return $getCustomers
添加到getValidCustomers()
答案 2 :(得分:1)
将return $getCustomers;
添加到getValidCustomers()
:D