I am currently attempting to extract data from a mysql DB and then place it into a multidimensional array, using the device name as a key.
The issue I'm having is that every time I iterate through the results the code im using kills the last item and replaces it.
Here is the code;
##sql connection##
$result = mysql_query(SELECT Device.DeviceID, Device.DeviceName, History.HistoryRec, History.HistoryDetectedDate from Device JOIN History ON Device.DeviceID=History.DeviceID WHERE History.Active_LastRound = 1 AND History.DetectedDate <= $hrs);
if (!$result){
die('invaild query:' . mysql_error());
while($row = mysql_fetch_array($result))
{
$last24hoursarray[$row['DeviceName']] = array($row['HistoryRec']);
}
So the issue i have is that my results set has multiple records with the same device name, and i cant work out how to put them into an array so that they do not overwrite the last item
for example i want
switch1 => issue1
switch1 => issue2
switch1 => issue3
switch2 => issue1
etc
but what i get is;
switch1 => issue3
switch2 => issue1
Thanks in advance. This is the first bit of PHP i have written, so please be gentle :D
mysql_*functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this article.