I'm not a php ninja, so please bear with me on my query. I have the following code (in simplified example format here as a lot of other irrelevant stuff is happening in the real code):
Database connection already successfully defined and handled by an include at the start of the php file.
// Define our $now value to compare times with
$now = time();
// Define the numerical timestamps required for calculating stuff
$min1st = 5140800; //59.5 days
$max1st = 5227200; //60.5 days
$min2nd = 7732800; //89.5 days
$max2nd = 7819200; //90.5 days
$delmar = 10368000; //120 days
// Get each relevant entry from the key table
try {
$stmt = $conn->prepare("SELECT * FROM keyTable WHERE `status` = 'neutral' ORDER BY `lastModified` ASC");
$stmt->execute();
$result = $stmt->fetchAll();
} catch(PDOException $e) { catchMySQLerror($e->getMessage()); }
// Set up some instance counters
$a = 0;
$b = 0;
$c = 0;
// Create some arrays to pop the data into from the next stage so we can use it again later
$arrA = array();
$arrB = array();
$arrC = array();
So far so good. The next part is designed to discover which of the database results have a "lastModified" value set within a specified timeframe, using some data we set up near the top. This works too, fairly well (I think).
foreach($result as $value) {
// Lets find the ones that qualify for first email notification
if((($value['lastModified'] + $min1st) < $now) && (($value['lastModified'] + $max1st) > $now)) {
// Now only the entries that have been untouched for 60 days from today are listed here. Yay! Send out an email to the people responsible and remind them! Get user data...
try {
$stmt = $conn->prepare("SELECT * FROM users WHERE `uID` = :uid");
$stmt->bindValue(':uid', $value['uID']);
$stmt->execute();
$uRes = $stmt->fetchAll();
} catch(PDOException $e) { catchMySQLerror($e->getMessage()); }
// Add +1 to the incremental count
$a++;
// Collect some data for the log email
$arrA[] = $value['entryKey']."-"$value['entryID'];
$arrA[] = $value['entryName'];
$arrA[] = $value['entryTitle'];
$arrA[] = $value['dateStarted'];
$arrA[] = $value['lastModified'];
$arrA[] = $uRes[0]['title']." ".$uRes[0]['firstName']." ".$uRes[0]['lastName'];
$arrA[] = $uRes[0]['email'];
Then it will on to send each person that gets turned up in this if. The code for sending the emails out etc works perfectly, so no need to bore you all with that. The same process is repeated each time with other parameters - you can likely guess how that works by observing the other numerical timestamp values near the top. So lets go to the end of this (which is where the question lies, after the:
}
}
And now here I want to pull all the data out of $arrA (and also the respective other arrays $arrB and $arrC) so I can pop that all into a tidy table then mail it off to admin so they know what exactly happened when this was all run.
My issue is, I do not know how to extract in a usable way, $arrA. If I var_dump($arrA); I successfully get all the stuff that should be in there but I don't see a way to order it in a nice row by row method per loop performed. I tend to end up with this when performing a var_dump($arrA);:
array(14) { [0]=> string(15) "ABC-63" [1]=> string(36) "Fish and Chips" [2]=> string(33) "Cod Disposal" [3]=> string(22) "1447283057" [4]=> string(22) "1447286317" [5]=> string(21) "Mr Bob Smith" [6]=> string(22) "[email protected]" [7]=> string(15) "XYZ-104" [8]=> string(23) "Blue Socks" [9]=> NULL [10]=> string(22) "1447286691" [11]=> string(22) "1447326523" [12]=> string(20) "Mrs Rosie Jones" [13]=> string(34) "[email protected]" }
Clearly there is output here for two data entries. I'd to know how to shape this into an output that would basically look like this:
<tr>
<td>ABC-63</td>
<td>Fish and Chips</td>
<td>Cod Disposal</td>
<td>1447283057</td>
<td>1447286317</td>
<td>Mr Bob Smith</td>
<td>[email protected]</td>
</tr>
<tr>
<td>XYZ-104</td>
<td>Blue Socks</td>
<td>NULL</td>
<td>1447286691</td>
<td>1447326523</td>
<td>Mrs Rosie Jones</td>
<td>[email protected]</td>
</tr>
Table start and end would obviously be in place before and after the loop respectively.
How can I achieve this result from $arrA? Do I need to modify the way I am storing this data in array's earlier on, in some manner, in order to have some sort of easy way to manage this output near the end?
Thanks in advance.