drewrockshard
drewrockshard

Reputation: 2071

PHP: Function to iterate results from another function and output

Seems like this would be pretty simple, however, I'm running into an issue:

Here's the code:

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();

Basically, the output right now is a list of the CustomerIDs (from updateValidCustomers()). I just want updateValidCustomers() to get the data from getValidCustomers() and then loop through it, so that I can run another query on it that will actually manipulate the database.

Any ideas?

Upvotes: 0

Views: 68

Answers (3)

Flambino
Flambino

Reputation: 18773

getValidCustomers() doesn't return anything - it just echoes

Add return $getCustomers to the end of getValidCustomers()

Upvotes: 2

Kaken Bok
Kaken Bok

Reputation: 3395

Add return $getCustomers; to getValidCustomers() :D

Upvotes: 1

Mark Elliot
Mark Elliot

Reputation: 77054

getValidCustomers doesn't return anything, maybe you mean this:

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

Upvotes: 2

Related Questions