Jump to content

Views ++


ecabrera
 Share

Recommended Posts

Ok i want it to make it that everything some clicks on a view the view goes up by one  so i did this

 

<?php
session_start();
$views = $_SESSION['views']++;
?>

 

and  echo the views like this

 

Views<?php echo $views; ?>

 

but it updates countines to add even if the video is a new video

 

Link to comment
Share on other sites

Hi.

 

Can you try to be a bit more specific? Or try to express yourself a bit more clearly?

 

The way I understood this is that you are trying to create a view counter for videos. Am I correct? Or are you trying to get the amount of views a specific person has viewed a single video?

 

Anyway: what your code does it increments the counter each time the code block is executed. If you want to get the views for specific videos you should for example assign a video ID or something similar to the view array.

 

$views = $_SESSION['views'][videoID']++;

 

In that way it increments the counter for a specific video, when user views another video another video ID is being incremented.

 

In case you want to get the total views, you should increment database view counts rather than session values.

 

Hope this makes any sense.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.