Hey guys... Am coding a forum using laravel, please how do I go about a function that count the number of people who visit a thread...?
I can answer this question in many ways, but first you need to tell us the type of data you are looking for. But a likely solution is this:
step 1: create a table called hits with fields - ID (autoincrement), thread_id (int), user_id (int), time (int)Step 2: each time the thread is visited, you can insert an entry into the table id, thread_id, user_id, time As for the time, you can use mysql timestamp or whatever you like
Step 3: to get the total number of people who visit the thread, do something like:
select count(*) from hits where thread_id=1 group by user_id (untested)
Thanks sir... Buh how I can get the hits is the problem, what php function do I use?
I would also suggest this too
From a laravel point of view, you can do this below
$hits = DB::select('select COUNT(*) AS total_hits from hits WHERE thread_id=2')->get();
$hits = DB::table('hits')->where('thread_id', 2)->get();
and get your results with
Howdy, Stranger!It looks like you've been lurking for a while.If you register, we will remember what you have read and notify you about new comments. You will also be able to participate in discussions.So if you'd like to get involved, register for an account, it'll only take you a minute!