Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2012, 04:33 AM   PM User | #1
rolperez
New to the CF scene

 
Join Date: Jan 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
rolperez is an unknown quantity at this point
Mysql 3 record in 1 hr = 1 record in another table

Hi!

I have a problem, i have a table, where the information of some devices are deposited if they have an alert, the structure of the table is this:

ID | SERVERID | TEMP | SENSOR | PROCESSED | DATETIME
1 | 12458788 | 23.3 | 1 | 0 |2012-01-16 16:50:01

I need to send the information to another table, if i have 3 records in 1 hour, the script sends only 1 record to another table or 2 followed records = 1 record in another table , do you have some ideas? i really really need help!

Thank for your time!!

[EDIT]

The table populates with various SERVERID's in an hour.....i need to send 1 record to another table for every 3 records in an hour of every serverid..... Thanks!!

Last edited by rolperez; 01-17-2012 at 06:48 AM.. Reason: missunderstood
rolperez is offline   Reply With Quote
Old 01-17-2012, 07:34 AM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
What would this 1 record be?

Also, why would you want to do this? Why not just pull the data from the other table (I'm assuming both tables are in the same database) as you need it?
__________________
Useful function to retrieve difference in times
The best PHP resource
A good PHP FAQ
PLEASE remember to wrap your code in [PHP] tags.
PHP Code:
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button 
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
BluePanther is offline   Reply With Quote
Old 01-17-2012, 08:34 AM   PM User | #3
rolperez
New to the CF scene

 
Join Date: Jan 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
rolperez is an unknown quantity at this point
Hi! Ihave 2 tables 'prealarms' and 'alarms'


the structure of the table 'prealarms' are this:
ID | SERVERID | TEMP | SENSOR | PROCESSED | DATETIME
1 | 12458788 | 23.3 | 1 | 0 |2012-01-16 16:50:01
2 | 12458789 | 24.3 | 1 | 0 |2012-01-16 16:55:01
3 | 12458786 | 21.3 | 1 | 0 |2012-01-16 16:55:01
4 | 12458788 | 21.3 | 1 | 0 |2012-01-16 16:55:01
etc..

and i need a query to separate the records by id and if there are three records in a lapse of one hour, send the 'serverid' to the 'alarms' table....only 1 record every 3 records found in a lapse of one hour...

Thanks!
rolperez is offline   Reply With Quote
Old 01-17-2012, 08:46 PM   PM User | #4
themousemaster
New Coder

 
Join Date: Sep 2011
Posts: 40
Thanks: 0
Thanked 7 Times in 7 Posts
themousemaster is an unknown quantity at this point
Is what you are trying to accomplish

--- for every hour, if it has 3 or more records, I need to make a record in the other table

or is it

--- for every hour, I need to write (#records / 3 rounded down) records to the other table

or is it

--- if there exists any record for which 2 other records are within 60 minutes of it, write a record to the other table

?



(The best solution will differ depending on which it is)

Last edited by themousemaster; 01-17-2012 at 08:50 PM..
themousemaster is offline   Reply With Quote
Old 01-17-2012, 08:53 PM   PM User | #5
rolperez
New to the CF scene

 
Join Date: Jan 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
rolperez is an unknown quantity at this point
One server send 1 record every 5 minutes, then the maximum number of records for 1 servers in 'prealarms' are 12....every 3 records i need to send 1 record to 'alarms'....

the best are this i think:


"--- for evert hour, if it has more than 3 records, I need to make a record in the other table"

Thanks!
rolperez is offline   Reply With Quote
Old 01-17-2012, 10:40 PM   PM User | #6
rolperez
New to the CF scene

 
Join Date: Jan 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
rolperez is an unknown quantity at this point
any suggestions?
rolperez is offline   Reply With Quote
Old 01-18-2012, 12:42 AM   PM User | #7
rolperez
New to the CF scene

 
Join Date: Jan 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
rolperez is an unknown quantity at this point
I thik i find an answer, if you have something better, please reply.

The code i was find is this:

Code:
SELECT
prealarmas.preid,
prealarmas.serverid,
prealarmas.temp,
prealarmas.visto,
prealarmas.datetime,
HOUR(prealarmas.datetime) AS h, COUNT(*)
FROM
prealarmas
WHERE
prealarmas.serverid =  '12345678887' AND
prealarmas.visto =  '0'
GROUP BY
h
And if h is = or > 3 , insert bla, bla... into 'alarms'

What doy you think?
rolperez is offline   Reply With Quote
Old 01-18-2012, 01:38 PM   PM User | #8
themousemaster
New Coder

 
Join Date: Sep 2011
Posts: 40
Thanks: 0
Thanked 7 Times in 7 Posts
themousemaster is an unknown quantity at this point
that would be similar to what I would have suggested.

You are grouping on "h" though, so you dont want to look for h >= 3, you want to look for COUNT(*) >= 3
themousemaster is offline   Reply With Quote
Users who have thanked themousemaster for this post:
rolperez (01-18-2012)
Reply

Bookmarks

Tags
datetime, mysql, records

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.