3
Hello, I am working on a warning system, when a data larger than normal is registered in the database an alert has to appear on the page where the user is browsing. The problem is that I don’t know how to check if an element has been added to the bank.
I am automatically taking my data from a PCD (weather station), if any of these data pass the registered limit by ADM, an alert will be shown to the user.
I have the following tables in my bank:
CREATE TABLE PARAMETROS_DE_ALERTAS (
PRA_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
PRA_VALOR_MAXIMO INTEGER(5) NOT NULL,
PRA_VALOR_MINIMO INTEGER NOT NULL,
PRA_COR_MINIMA VARCHAR(30) NOT NULL,
PRA_COR_MAXIMA VARCHAR(30) NOT NULL,
SEN_ID INTEGER NOT NULL
);
This table is the parameter for alerts, where the minimum and maximum measurement coming from the PCD will be registered to be an alert.
CREATE TABLE MEDICOES (
MED_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
MED_DADO VARCHAR(10) NOT NULL,
MED_DATA_HORA_MEDICAO DATETIME NOT NULL,
API_ID INTEGER,
SEN_ID INTEGER NOT NULL
);
This is the measurement table, where you will store the data from the PCD.
CREATE TABLE ALERTAS_CRITICOS (
ALC_DATA_HORA_ALERTA DATETIME NOT NULL,
ALC_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
ALC_VALOR_MEDICAO FLOAT NOT NULL,
SEN_ID INTEGER NOT NULL
);
The system must add a record of this table if the measurement data is greater or less than the parameters. After this critical alert is registered, the system must show an alert to the user who is browsing any page of my site.
The problem is that I don’t know how to check if a record has been added to the bank.
What kind of element you refer to ?
– MagicHat
A table even, for example, I will get my data from a PCD (a weather station), which will send me data such as the water level of a river, if the level exceeds the limit registered by ADM, should show an alert to the user.
– Nicolas Vilela
Put an example in your question, this section that defines the limit.
– MagicHat
What language you are using, in the application ?
– MagicHat
PHP to connect to the database and ajax to control php functions.
– Nicolas Vilela
As you are receiving this data, you can put a snippet of php code?
– MagicHat
I still haven’t gotten to the part of integrating my project to PCD, so far I’m adding the records directly by SQL code.
– Nicolas Vilela
So I guess you have to make a comparison when inserting into the if(x > y || x < z){echo "has been added";} something like this... is this what you’re looking for? But can make queries sql oara check...
– MagicHat
Yes, this part will add a critical alert record to the database, but I would like an alert to appear to the user who is browsing on any page of my website, So I guess I’d have to use a method that would check if a critical alert record was added to the bank. Or when the system adds the critical alert send something that fires a Istener on the pages that will show the alert.
– Nicolas Vilela
Type, if you will have a script that will be updating the PDC information,, that is to say this script will have to be executed automatically, from time to time, and the moment the return is within the parameters it alerts to any user on any page, that’s it?
– MagicHat
This, one way I thought of performing this action was to create a script that would check whether a critical alert was added to the database from time to time. I believe that if I store in a var what was the last id entered to the critical alerts table, and check from time to time if the last record inserted is > to the variable I saved, then it would trigger the alert. You think that would work?
– Nicolas Vilela
I think so, there are many ways to achieve what you want. I think a block diagram might help you decide the best time to do the check. It can be at the time of consultation in the PDC, at the time of insertion in the bank, or through periodic consultations. The most important (I think) is to plan these steps well and build according to your goal.
– MagicHat
Yes, thank you very much Magichat, now I have more or less the idea of how I will do this formulated!
– Nicolas Vilela
This may help or complicate, it is not my intention to complicate. https://dev.mysql.com/doc/refman/5.5/en/signal.html
– MagicHat