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 6878185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:41:33+00:00 2026-05-27T04:41:33+00:00

The structure of my mysql table is: CREATE TABLE IF NOT EXISTS `tb_hour_counts` (

  • 0

The structure of my mysql table is:

CREATE TABLE IF NOT EXISTS `tb_hour_counts` (
  `date` date NOT NULL,
  `subid` int(20) NOT NULL,
  `unique_ids` int(20) NOT NULL,
  `total_ids` int(20) NOT NULL,
  `unique_ips` int(20) NOT NULL,
  `total_ips` int(20) NOT NULL,
  `global` int(20) NOT NULL,
  `time` text NOT NULL,
  UNIQUE KEY `ind_1` (`date`,`time`(5),`subid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I have an array of data like:

$array = array(
    '0' => array(
        'date' => '2011-10-10',
        'time' => '00:00',
        'subid' => '2',
        'unique_ids' => '588'
    ),
    '1' => array(
        'date' => '2011-10-10',
        'time' => '00:00',
        'subid' => '2',
        'unique_ips' => '3'
    ),
    '2' => array(
        'date' => '2011-10-10',
        'time' => '00:00',
        'subid' => '2',
        'total_ids' => '3995'
    ),
    '3' => array(
        'date' => '2011-10-10',
        'time' => '00:00',
        'subid' => '2',
        'total_ips' => '1000'
    ),
    '4' => array(
        'date' => '2011-10-10',
        'time' => '00:00',
        'subid' => '2',
        'global' => '1000'
    ),
    '5' => array(
        'date' => '2011-10-10',
        'time' => '01:00',
        'subid' => '3',
        'unique_ids' => '766'
    ),
    '6' => array(
        'date' => '2011-10-10',
        'time' => '01:00',
        'subid' => '3',
        'unique_ips' => '10'
    ),
    '7' => array(
        'date' => '2011-10-10',
        'time' => '01:00',
        'subid' => '3',
        'total_ids' => '934'
    ),
    '8' => array(
        'date' => '2011-10-10',
        'time' => '01:00',
        'subid' => '3',
        'total_ips' => '950'
    ),
    '9' => array(
        'date' => '2011-10-10',
        'time' => '01:00',
        'subid' => '3',
        'global' => '7554'
    )
);

The goal is to insert the data into the table. The result of inserting the data from this array should be the following:

result

I believe this could be done either by mysql request, or by preparing the array for usual insert.

  • 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-05-27T04:41:33+00:00Added an answer on May 27, 2026 at 4:41 am

    It’s very messy, but:

    // your array below
    $array = array();
    
    $newArray = array();
    
    foreach($array as $item){
            $newArray[$item['subid']]['date'] = $item['date'];
            $item['time'] > $newArray[$item['subid']]['time'] ? $newArray[$item['subid']]['time'] = $item['time'] : null;
            $newArray[$item['subid']]['unique_ids'] += $item['unique_ids'];
            $newArray[$item['subid']]['total_ids'] += $item['total_ids'];
            $newArray[$item['subid']]['unique_ips'] += $item['unique_ips'];
            $newArray[$item['subid']]['total_ips'] += $item['total_ips'];
            $newArray[$item['subid']]['global'] += $item['global'];
    }
    
    print_r($newArray);
    

    This gives you:

    Array
    (
        [2] => Array
            (
                [date] => 2011-10-10
                [time] => 00:00
                [unique_ids] => 588
                [total_ids] => 3995
                [unique_ips] => 3
                [total_ips] => 1000
                [global] => 1000
            )
    
        [3] => Array
            (
                [date] => 2011-10-10
                [time] => 01:00
                [unique_ids] => 766
                [total_ids] => 934
                [unique_ips] => 10
                [total_ips] => 950
                [global] => 7554
            )
    
    )
    

    You can then just do something like:

    foreach($newArray as $key=>$value){
            echo "INSERT INTO `table` ('{$value['date']}',{$key},{$value['total_ids']})"; // etc. etc.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a table successfully created in MySQL: CREATE TABLE IF NOT EXISTS MESSAGE
I have in my MySQL database these two tables: CREATE TABLE IF NOT EXISTS
We have a MySQL table with about 3.5 million IP entries. The structure: CREATE
newb question there. Having MySQL database/tables structure below: CREATE DATABASE `dbTest` CREATE TABLE IF
What's the best way to structure a MySQL table for storing admin settings? Like
I have the following MySQL table structure: num field company phone website 1 Gas
I have a MySQL table with the structure: beverages_log(id, users_id, beverages_id, timestamp) I'm trying
I am using a MySQL table called login with the following structure: loginid, username,

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.