how can I add the client_id to an array if a transaction is in the date range and then REMOVE it aftwerwards if another transaction is not in the date range?
This is the code below. Note there is an array called non_returns_list. This is where i want to stick the client_id for each non returning client.
The way it is meant to work is like this:
1. Parse through the transactions from OLDEST to NEWEST.
2. If a transaction comes up that is older than the non return date, then add the client_id to the non_returns_list. (as this would indicate they have not returned since non return date)
3. IF though, they have a newer transaction later in the array, that is IN the date range (is not older than the cut off date) then REMOVE that clients ID from the non_returns_list array.
In this way it would keep adding and subtracting the client_id to the array until the loop was complete and all client_id's left in the array would be for clients that have got transactions older than the cut off date but have not done any new transactions this side of the cut off date.
Man I hope that made sense Smile
Below is the code I have for determining the date etc, that works, but the question is: how can I add the client_id to the array and then REMOVE it if it is not in the date range?
Code: Select all
$date_data_array = find_date_from_today($weeks); //get the date info for use below, anything beyond this date is considered a non return client
$report_client_info_further_array = report_client_info_further();
//create arrays to stick all the client and transaction data into
$client_list = array();
$transaction_list = array();
$non_returns_list = array();
// Grab the client data
$sql = "SELECT * FROM clients ORDER BY id ASC";
$content = mysql_query($sql);
while ($row = mysql_fetch_array($content))
{
$client_list[] = $row;
}
// Grab all transactions
$sql = "SELECT * FROM transactions ORDER BY id ASC";
$content = mysql_query($sql);
while ($row = mysql_fetch_array($content))
{
$transaction_list[] = $row;
}
// Now loop through the client list and compare to the transaction in a second loop
for ($i = 0; $i < count($client_list); $i++)
{
$client_id = $client_list[$i]['id'];
for ($j = 0; $j < count($transaction_list); $j++)
{
//setup the vars for use in the next loop
$check_date = $transaction_list[$j]['date'];
$cut_off_date = $date_data_array[adjusted];
if ($transaction_list[$j]['cust_id'] == $client_id)
{
// Now you are on the part of the loop where the transactions match the customer
// Do your things here then exit
//echo "client_id = $client_id ::: trans_client_id = $check_date($cut_off_date) <br>";
if ($check_date < $cut_off_date)
{
//add the non return client to the non_returns_list array using the client_id
echo "<br>add $client_id to array";
}
else
{
///REMOVE the non return client to the non_returns_list array using the client_id
echo " - remove $client_id from array<br>";
}
} //End client = transaction loop
} //End transaction loop
} //End client loopproduces:
Code:
Code: Select all
add 18 to array
add 19 to array
add 19 to array
add 19 to array - remove 19 from array
- remove 19 from array
- remove 19 from array
add 20 to array
add 21 to array - remove 21 from array
- remove 21 from array
- remove 21 from array
add 22 to array
add 22 to array
add 22 to array
add 23 to array
add 23 to array