Self_Taught_Still_Learning Posted July 25, 2020 Share Posted July 25, 2020 Hi, thanks for taking the time to read this. Probably pretty basic for most but i'm struggling even after watching videos and reading different forum posts. Here is what i am trying to do. I want to watch some data without the need to refreshing the page. The database stores the data using time() and then runs through a time function to convert it to a seconds and minute output(examples "00s"/"13m 44s"). I need to pull this and have it refresh automatically and been told due to how basic this is i should be able to do it in javascript using fetch() but i am struggling to get pages talking and just completely confused how to pull the data in php and then pull using javascript. Any advise would be greatly appreciated as well as and examples and explanations on why you are doing what you are. Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/ Share on other sites More sharing options...
requinix Posted July 25, 2020 Share Posted July 25, 2020 I don't understand what the database has to do with this. Is the time constantly changing? It's one value when you load the page and the potentially another value sometime later? Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580056 Share on other sites More sharing options...
Self_Taught_Still_Learning Posted July 25, 2020 Author Share Posted July 25, 2020 (edited) So it's to compare 2 figures simultaneously. Value 1 = Time Value 2 = Time Both times are constantly changing yes.  <table> <tr> <td>Name 1</td><td>Name 2</td> </tr> <tr> <td>Time 1</td><td>Time 2</td> </tr> </table> So the times above would be pulled from the database and updated every 2-5 seconds Edited July 25, 2020 by Self_Taught_Still_Learning Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580057 Share on other sites More sharing options...
requinix Posted July 25, 2020 Share Posted July 25, 2020 I'm still kinda skeptical but okay. What you want is AJAX. fetch() can do that for you. Make a PHP script that gets the time from the database and outputs it. Or if you're feeling up to it, put that code into some existing file where you feel it makes sense. Either way you need to end up with a URL that you can visit (in your browser) to see the time value. No HTML or anything. Just the value. Then play around with the fetch() examples and whatever else about it you want to read. If you fetch() that URL with the time then you'll get the time. Then you do stuff with Javascript. I don't know what because you've been pretty vague about everything. Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580058 Share on other sites More sharing options...
Self_Taught_Still_Learning Posted July 25, 2020 Author Share Posted July 25, 2020 38 minutes ago, requinix said: I don't understand what the database has to do with this. Is the time constantly changing? It's one value when you load the page and the potentially another value sometime later? I've got 2 rows in a database table for 2 different accounts, each time an account changes page, the time changes in the database and is recorded. I want to display both accounts side by side and have it pull that time running through a function to convert it into time gone by but have it refresh every 2-5 seconds without needing to keep refreshing the page manually. So on first load, user 1 and user 2 will be on 00s for example if both have just moved, then on next refresh user 2 hasn't moved but user 1 has so it would display user 1 as 00s and user 2 as 02s Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580060 Share on other sites More sharing options...
requinix Posted July 25, 2020 Share Posted July 25, 2020 Ah okay, that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580061 Share on other sites More sharing options...
maxxd Posted July 26, 2020 Share Posted July 26, 2020 I'm honestly not sure your setup makes sense to me, but it sounds like you may want to look into web workers and forgo the database polling entirely, unless I'm misunderstanding the goal. Which is, quite honestly, very possible at this point. Quote Link to comment https://forums.phpfreaks.com/topic/311219-fetch-help-and-understanding/#findComment-1580071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.