Page 1 of 1

How to convert a reminder app in JS to PHP/mysqli

Posted: Tue Dec 06, 2016 1:33 pm
by gautamz07
I wanted to make a basic prototype reminder app and so i first built it in javascript , so i plain JS i am just basically accepting time from the user and then some Math calculation to return the difference in seconds and then i use a setTimeout like so:

Code: Select all

setTimeout(function(){
    // Remind the user of a task.
}, /* difference in secounds from current time to what the user has entered */)
The above is basically a oversimplified version of my JS application , but now suppose i have to write the same in PHP , how would this work , i mean ofcoure i will take the time and store it in the database , but then how exactly would a reminder app work in PHP/MySqli ??

This my be a very broad question, but i just can't think of anything right now and so i taught it would be best to post and get an opinion .

Thank you.
Gautam.

Re: How to convert a reminder app in JS to PHP/mysqli

Posted: Tue Dec 06, 2016 1:51 pm
by Celauran
How is this intended to work? Send out a notification to the user after a given time? Maybe look at something like Pusher? https://github.com/pusher/pusher-http-php

Re: How to convert a reminder app in JS to PHP/mysqli

Posted: Tue Dec 06, 2016 2:04 pm
by gautamz07
@celauran yes , so of now i just send a HTML5 notification to the user once the setTimeout runs .
https://developer.mozilla.org/en/docs/W ... tification

Will checkout the link , thanks

Re: How to convert a reminder app in JS to PHP/mysqli

Posted: Thu Dec 08, 2016 6:25 am
by gautamz07
@celauran , Thanks for the answer , but is there a easier solution to building a JS,PHP,Mysqli application that sends HTML5 notifications to users at a given time ??

Re: How to convert a reminder app in JS to PHP/mysqli

Posted: Thu Dec 08, 2016 7:00 am
by Celauran
What are you trying to accomplish? PHP isn't necessarily the right tool for the job.

Re: How to convert a reminder app in JS to PHP/mysqli

Posted: Fri Dec 09, 2016 1:23 am
by gautamz07
@celauran ! yes i had the same concern that PHP might not be the right fit for the job. so i'll explain in detail how this app works so far,

So suppose i have two two input elements on myfrontend , one accepts a task and the other accepts a date and time in the future.

So the input element looks something like http://imgur.com/4a1Ko9T.

Now when the user in the frontEnd enters a task and also a date and time and clicks on submit , so of now i am storing these details in localstorage and simultaniously also a setTimeout is activated to notify the user of the task(to whenever the user has set the time to in the frontEnd). So once the settimeout Runs basially a function is called which notifies the user with a HTML5 notification , it just mentions the task to be performed.

Now obviuosly there are a couple of issues with this one being localStorage can be easily manupulated using the dev tools , the other being localstorage can't be accessed in another browser I.E. the localstorage object stored in one browser can't be accessed in another browser.

the reason i want to use PHP/mySqli is that obviously storing the users tasks in a database is much safer , so that a clear advantage. Iám just thinking , well how do i run a timer(or something of that sort in PHP) , so that the user is notified.


ONE WAY TO DO THIS WOULD BE::

- Accept user input (Task and date/time).
- Save date to the database/ Simultaniously activate a setTimeout to run.
- When the setTimeout Runs query the database again , get the tasks and show the user in an HTML5 notification. (Here i am asssuming two things , that no two tasks will be set to the same time as when the setTimeout runs , it will compare the current time to the time of all the tasks in the database and the tasks that has a time set to the current time , will be selected.)

Another scenario would be .....
- User enters a Task and date/time .
- Save date to the database/ Simultaniously activate a setTimeout to run.
- user Closes the browser.
- User reopens the browser and NOW ......... Run a Query to select all the tasks and set a setTimeout for each task.
- When the setTimeout Runs query the database again , get the tasks and show the user in an HTML5 notification.

Ok , so i have listed a approach above , @celaurian , i would like to know what your opinion is of the above approach.


Since you mentioned "the right tool" ... A Firefox or chrome browser extension would be a perfect fit for this kind of an app... and you might even be thinking well , why would the user want to keep a separate tab open in the browser just to be notified of a task .... Why not just build a brower extension then ???

Well the answer to the above is i just as of now , with my current requirements need to build this application as a web app , w()hen the user indeed has a tab open for the notification to be displayed. (in the future i will find a way around how to close the tab and still notify the user in someway.)

@celauran , if you have any questions please feel free to ask.

BTW , this app as of now is just for my personal use , not for any commercial purpose.