can anyone giv the main concept of "videos being watched now" u see that on youtube or some other video sharing site. how to make such thing that can track which videos r being watched & return those ???
Simple concept: When someone starts watching video insert a record in database with current time. So videos watched now are for example 5 records sortred by date desc. Clean this database for records older than some given time. More details - make a record through ajax request some time after page load so make sure a person is wathching video and didn't go to another page.
view.php?id=12 Code (markup): $id = $_GET['id']; $timestamp = time(); $reg = mysql_query("INSERT INTO activity (video_id, timestamp) VALUES ('$id', '$timestamp')") or die(mysql_error()); PHP: Make another query to fetch data about videos which timestamp field is bigger than the current time minus 3 minutes ( just an example ) and print them out.
ok i now understand the first step (insert) in view.php file i'll add that code..so whenevr someone open it, it will write to DB but how to clean it. i mean clean that DB table, which tables r older than 5 minutes
no he means just clear the table of any records that are for example older than 5 minutes obviously you can tell the record's age by the timestamp that you have recorded it with
Well, using database structure by sunchiqua $timestamp = time()-5*60; $reg = mysql_query("DELETE FROM activity WHERE timestamp < '$timestamp')") or die(mysql_error()); PHP:
You may not even want to delete it so quickly. $timelimit = time() - 180; $get = mysql_query("SELECT * FROM activity WHERE timestamp < '$timelimit' ORDER BY timestamp DESC LIMIT 0, 15") or die(mysql_error()); PHP: Once in a day or so, let the cron flush the table ( partially .. let's say, everything that's older than 30 minutes ).
I guess when selecting you should use "greater than" condition, cause if you use "less than" you'll get rows older than given timestamp.