我不是一個php忍者,所以請在我的查詢中忍受我。我有以下代碼(在這裏簡化示例格式,因爲很多其他不相關的東西正在實際代碼中發生):如何從php數組中以有序方式提取數據?
數據庫連接已經成功定義並由php文件開頭處的include處理。
// 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();
到目前爲止好。下一部分旨在通過使用我們在頂部附近設置的一些數據來發現哪些數據庫結果在指定的時間範圍內設置了「lastModified」值。這工作也相當好(我認爲)。
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'];
然後它會發送每個人在這if
出現。用於發送電子郵件等的代碼完美無缺,所以不需要爲此帶來任何煩惱。每次使用其他參數重複相同的過程 - 您可能會通過觀察頂部附近的其他數字時間戳值來猜測工作原理。所以,讓我們進入本月底(這是問題所在,在後:
}
}
現在在這裏,我想拉的所有數據從$ ARRA的(以及相應的其他陣列$ ARRB和$ arrC),所以我可以將它們全部放入一個整潔的表格中,然後將它郵寄給管理員,這樣他們就可以知道在全部運行時發生了什麼。
我的問題是,我不知道如何以可用的方式提取,$ arrA。If I var_dump($arrA);
我成功地獲得了應該在那裏的所有東西,但是我沒有看到一種方法來按照每個循環執行的行方法對它進行排序,我傾向於在執行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]" }
顯然這裏有兩個數據輸入的輸出。我倒是知道如何塑造成一個輸出將基本上是這樣的:
<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>
表開始和結束顯然是到位前,分別在循環之後。
如何從$ arrA中獲得這個結果?我是否需要以某種方式修改我以前在數組中存儲這些數據的方式,以便在接近尾聲時能夠以某種簡單的方式管理該輸出?
在此先感謝。
認爲我的輸出可能不夠清晰。更新輸出需要更好理解... – df0