Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:31:00+00:00 2026-06-10T06:31:00+00:00

I am currently attempting to extract data from a mysql DB and then place

  • 0

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 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:31:02+00:00Added an answer on June 10, 2026 at 6:31 am

    PHP Array keys are unique, so you would not be able to store multiple values under the same key, try the following:

    while($row = mysql_fetch_array($result)) {
            $last24hoursarray[$row['DeviceName']][] = $row['HistoryRec'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to implement a custom gridview interface to display data from
I'm currently attempting to retrieve a list of objects from my database using jQuery.
I'm currently attempting to use the Windows Powerpack DataRepeater control to display data from
I'm currently attempting to print a document from WPF. I'm using the web browser
I am attempting to extract all data from a file with one regex expression.
I am currently attempting to use Lucene to search data populated in an index.
I'm playing with using Regex to modify Twitter posts. I'm currently attempting to trim
Currently attempting to get some code to compile using Lejos for the Lego NXT
I am currently attempting to follow along with section 10.38 from RoR Tutorial. All
I'm currently attempting to read information about an object from the web.config file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.