Display the database in mysql from datetime= now() - php

I want to show the updated values via php since the time i login my page not the previous values. How can i do that. Especially, the data will update frequently and i want to update the data table in my page continuously.

You can use nodejs with php to update real time data.
The mysql query LISTEN and NOTIFY along with triggers you can have NOTIFY events fire when certain queries are performed on specific tables with nodejs.
This links may helpful.
http://nodejs.org/
http://bjorngylling.com/2011-04-13/postgres-listen-notify-with-node-js.html

Related

How can i keep my web receiving mysql data

first of all.. sorry for my english, i'll try my best!
I have a web application where i show info about Data stored in my Mysql. I Would like to make it more dynamic and if some new information appear in my DB then update my web content without a refresh. I was thinking about Ajax. Every minute send an ajax function asking for some new data... but it's not a good idea 'cause it can be stressing for my server.
What's the best way to do it?
Thanks a lot for your time!
You could use something like Firebase which automatically pushes data to the client when changes occur in the backend database, but that means that you would have to store all your data in Firebase instead of in your Mysql database.
Apart from a service like that, one option is to use an ajax call to fetch new data, but only when new data is available. I don't know how your data is structured, or what kind of data it is, but one solution to minimize the load on your server is to have a database table with a timestamp column that's updated every time relevant data is changed, added or deleted in your database. Use ajax to fetch only this timestamp every minute and if the timestamp has changed since you last checked it, make another ajax call to fetch the actual data.

PHP jQuery MySQL refesh instant

I have made a progress sheet that between 1-30 users will update constantly throughout the course of the day. It’s controlled by PHP and jQuery and all the data is stored in a mySql database.
It’s quite slow on the live server, because I re query on searches and filters. I was wondering where is the best place to store the result, because I only need the latest updates but I do not need to constantly filter and update.
Is it okay to store that kind of data in a session or who else could I store it to avoid full query on every change/search or when the page changes?
I did look into memcached, but I ended up redesigning it.
I used jQuery to filter the records using hide() and show() on the data attributes that matched, instead of using a “LIKE '%Darren%'” SQL query.
This puts the load on the user’s terminal opposed to my server (Try to keep the animations to a minimum, to keep the memory usage low).
Then I store a timestamp of the last update on the user’s terminal in the HTML then run a
“SELECT id FROW progress WHERE updated > '2014-02-20 16:54:30' LIMIT 1” query periodically.
If I get 1 record back I use Ajax to a full update and refresh the areas required with fresh HTML.
Doing it this way has made it so much quicker and smoother.
I how this helps, if you need more info let me know!

Event Scheduler to multiple MySQL databases

I am trying to figure out if its possible to have EVENT SCHEDULER take data from one database and update it to another. I checked mysql site and google but there isn't any info on this. I know how to create events and understand the process. I am thinking of using php and mysql but not sure if that would work.
Why I need this:
Database A - gets a lot of traffic
Database B - gets little traffic
I want to run certain queries (counts mostly) to run once a day from Database A. Then store the results inside Database B. This way when some loads a page that has to do a count, it wont run the count query but instead just SELECT * FROM database B. Making it load faster.
I think what you need to do is to replicate your databases!
For example you can specify Database 'A' as your publisher and Database 'B' as your subscriber. There are lot of articles on the internet regarding replicating MySQL databases. Google and find out. Anyway have a look at this question over here MySQL Event Scheduler on a specific time everyday. This might give you an idea on what to achieve.

Action Listener in PHP/Mysql, whenever any record inserted into table?

Is their any method/way that we come to know, any change occurs in desired table?
I have implemented one solution that it checks in db every 30 sec, that is if any change occur in chats table then refresh my chats listing. it waists lot of performance and slow down the site.
Is their any way that our action listener only calls whenever any row is inserted in table?
Any idea?
You may create table with notifications (which will always contains just unread messages for last 2 hours or so) and then create trigger [syntax] that will create new notification each time change occurs:
CREATE TRIGGER create_notification AFTER INSERT ON chats
FOR EACH ROW INSERT INTO notifications (...) VALUES( NEW.col1, NEW.col2)...
Then you'll end up with much smaller (and faster) database table.
There are some alternatives like writing a socket server but I think it would be less resource effective than pooling database plus I have a bad experience running php scripts for a long time.
well in your scenario you need a listener, which tracks the moment the new row of chat is inserted to the database.
It will be easier if you emit chat message to the users before you insert it into the database.
You can use socket. you can either use nodejs+socket.io to perform this. Here is bit about that
socket.io and node.js to send message to particular client
You can also look this article
https://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0

MYSQL moving information with php

I am wondering if it is possible to automate or by button press to move mysql table information from one table to another table deleting it from the first table and putting it in another table? Using php.
My mysql table is big and the page that adds the information to that table has 70 query's on it which slows the page refresh times. I need to move information from the first table to the second at a certain time of day everyday so that those querys don't have to look through all of my giant 27k row table.
Is this possible?
Also if someone could help me with my comment on this page I would be grateful.
link text
PHP doesn't have a constantly running server you can schedule background tasks with.
If you have access to the server you can set up a cron job (or scheduled task under windows) to run the PHP script for you.
Or (and this isnt so nice) you can put the script on the webserver and call it manually at the appropriate time by entering the URL in your browser.
A 27k row table is small by SQL standards, as long as it is properly indexed.
For instance, if you don't care about data from yesterday, you can add an indexed date column and filter with WHERE myDate > NOW() - INTERVAL 1 DAY, and SQL will automatically restrict the query to the rows younger than 24 hours.
I am wondering if it is possible to automate or by button press to move mysql table information from one table to another table deleting it from the first table and putting it in another table? Using php.
You can initiate it from PHP, but what you ask is effectively MySQL's domain.
It can be accomplished in two statements:
Use an INSERT INTO statement to copy the rows from the old table to the new one
Delete the old table
My preference would be that this occurs in a stored procedure for sake of a transaction and ease of execution (in case you want it initiated by CRON/etc) because it would be easier to call one thing vs a couple or more.
27k is not very big table and MySQL should work ok with that. Do you have all the required indexes? Did you used EXPLAIN on your slow queries?
As for the question about moving data from one table to another - create a php script that will be run by CRON and will move rows one by one. What's the problem here?

Categories