How can i keep my web receiving mysql data - php

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.

Related

Storing values without DB

I am developing a website using HTML5, js, php,... I have a doubt and I don't know if can be solved.
I have a settings tabs, where I select some alerts from values received from thingspeak. For example using a temperature sensor, I select from 10 to 20 ºC the alert and then depends on the value received it will be shown a notification. I have not developed this part yet, but I want to know if would be possible to save that. I have a DB for the user details, but I want to save this without saving this into a DB.
The main problem of this I think is when you close the web browser and the slider values will be restored when you open again. How can I save those alert settings? Should the best option to store in a db? How can I do this?, because can have more than 10 alerts, and I don't know how to store this in a db
Cookies would do a pretty nice job especially if you can handle their dimensional form but you have to put in mind that if you personally want these data/information in the nearest/far future then you have no choice but to stick with the conventional DB.

Suggestion on copying data from server database to android device sqlite

I'm developing an Android app for salesman, so they can use their device to save their order. Specifically, every morning the salesman would go to the office and fetch the data for that day.
Currently, I can get the data by sending a request to php file, and like common practice we insert those data into sqlite in the Android so it can work offline. However, with current approach the device needs 6-8 seconds on getting the data and inserting those data to sqlite. As the data grow bigger I think it would make it slower. What I had found is that the process of inserting data into sqlite takes quite amount of time.
So, I've been thinking about dumping all data that is needed by the salesman into a sqlite file, so I could send only that file which I guess is more efficient. Can you please lead me on how to do that? Or is there any other way which is more efficient approach for this issue?
Note:
Server DB: Mysql
Server: PHP
You can do here different approach to achieve loading speed:
If your data can be pre-loaded with apk, you can just store those inside .apk and when user download app, it will be there, you just need to call remaining updated data.
If you need refreshed data every time, you can do call chunk of data from server in multiple calls, which will fetch and store data in database and update on UI.
If data is not too much, (I say, if there are 200-300 data, we should not consider it much more) you can do simple thing:
When you call network call for fetching data, you should pass that data objects to database for storing and at same time (before storing in db), just return the entire list object to Activity/Fragment, so it will have the data and you can see those data to user, in mean time, it will store in database.
Also, you can use no-sql in side sqlite, so you don't need to parse objects every time (which is costly compare to no-sql) and store all data in sql as entire object and whenever require, just fetch from db and parse it as per requirement.
Thanks to #Skynet for mentioning transaction, it does improve the process alot.. So I'll stay with this approach for now..
You can do something like so:
db.beginTransaction();
try {
saveCustomer();
db.setTransactionSuccessful();
} catch {
//Error in between database transaction
} finally {
db.endTransaction();
}
For more explanation: Android Database Transaction..

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!

Autoprocess in PHP

I'm doing with PHP. I have a form. Each time users submit that form, I want to save these data to database first (to save time for users) then deal with these data later. But I don't know how to deal with these data automatically. Any code can auto process in server to treat these data automatically everytime having new record in database?
Did you get my question? Any suggestions? Thanks in advanced!
You could use 'Stored Routines' that get triggered when the data changes, see:
http://dev.mysql.com/doc/refman/5.0/en/stored-routines.html
or, slightly less elegant, use a cronjob that launches every set amount of time and have a "processed" flag on the database that allows the script to know what records it has already processed and which ones it hasn't and act accordingly.
You might be looking for trigger http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

FullCalendar - clientEvents: can't send the returned array to php without losing the date/time values

What I'm trying to do is pretty simple. When an event is created or resized/moved in the calendar, I update my database. In my database I don't have a row for each event, I have instead a json array in a field which contains all the events for a particular section (that will make sense to you later).
So what I'm trying to do is each time an event is created/resized/moved I get back all the events from the calendar and send them through ajax to the server, and store them in the database. The problem I have is that I lose the date/time information in my php script. I guess it has something to do with the fact that on the javascript side it is encoded differently that on the php side.
I can't update only the event that is resized because in my database, I don't have (yet) a way to differentiate the events. So I need to get them all and make my beautiful json array and put it in the db.
So, anyone get some ideas?
Thx
Guill

Categories