Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 05-03-2013, 06:48 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
How to keep a Track how many times User Clicked Previous/Next

I have one code in that I want to implement Next Previous Option.

I have this code which only returns 1, i want some function which keeps a track on the Clicks on Previous or Next Hyper Link, based on that I will Query Those dates values from Database


below is my code it returns only 1

HTML Code:
HTML <html> <head><title>Global Variable Test 1</title></head> <body> <script type="text/javascript" src="clickCount.js"></script> <a href="#" onClick="countClicks();"><img src="arrow.gif" /></a> </body> </html>
JavaScript


PHP Code:
var counter 0;
  function 
countClicks() {
        
counter++;
        if(
counter 1)
       
alert("Waah, stop clicking!");
        else
       
alert('Number of clicks:' counter);
  } 
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 05-05-2013, 12:29 AM
thanhtran thanhtran is offline
Junior Member
 
Join Date: 05-05-13
Posts: 2
iTrader: 0 / 0%
I can paste this code into the public??
 
Reply With Quote
  #3  
Old 05-05-2013, 07:24 PM
snakeair snakeair is offline
Super Moderator - Rest in Peace 2018
 
Join Date: 12-31-07
Location: Medford, NJ
Posts: 54,771
iTrader: 3 / 100%
Quote:
Originally Posted by thanhtran View Post
I can paste this code into the public??
??

Please explain.
 
Reply With Quote
  #4  
Old 05-06-2013, 05:42 AM
snakeair snakeair is offline
Super Moderator - Rest in Peace 2018
 
Join Date: 12-31-07
Location: Medford, NJ
Posts: 54,771
iTrader: 3 / 100%
Quote:
Originally Posted by MagicTheme View Post
You can use statcounter to do that.
Any help on the code the thread creator posted?
 
Reply With Quote
  #5  
Old 05-06-2013, 07:17 AM
beanz750 beanz750 is offline
Junior Member
 
Join Date: 05-05-13
Posts: 7
iTrader: 0 / 0%
Hmmmm?

I usually just use php GET to do this. I believe it is the usual method for dynamic page loading.

Simply place the counter into your link:

PHP Code:

<?php

//This checks the URL for the proper page number
$pageNum $_GET["pageNum"];

/*
//If this is the first page you won't have the page number in the URL, so just declare it as page 1
$pageNum = 1;
*/ 
//Add 1 for the next page
$nextPage $pageNum++;
//Subtract 1 for the previous page
$previousPage $pageNum--;

//If it's page 1 don't display the previous page link
if($pageNum != 1){
    echo 
'<a href ="mypage.php?page='.$previousPage.'">Previous Page</a> | <a href ="mypage.php?page='.$nextPage.'">Next Page</a>';
}else{
    echo 
'<a href ="mypage.php?page='.$nextPage.'">Next Page</a>';
}

?>
The URL will look like "mypage.php?page=5"
The GET method will read the 5 in the URL as the current page Number: "$pageNum = 5"

Last edited by beanz750; 05-06-2013 at 07:22 AM. Reason: needed more explination
 
Reply With Quote
  #6  
Old 05-07-2013, 07:27 AM
stephen001 stephen001 is offline
Contributing Member
 
Join Date: 04-25-13
Posts: 89
iTrader: 0 / 0%
Quote:
Originally Posted by beanz750 View Post
Hmmmm?

I usually just use php GET to do this. I believe it is the usual method for dynamic page loading.

Simply place the counter into your link:

PHP Code:

<?php

//This checks the URL for the proper page number
$pageNum $_GET["pageNum"];

/*
//If this is the first page you won't have the page number in the URL, so just declare it as page 1
$pageNum = 1;
*/ 
//Add 1 for the next page
$nextPage $pageNum++;
//Subtract 1 for the previous page
$previousPage $pageNum--;

//If it's page 1 don't display the previous page link
if($pageNum != 1){
    echo 
'<a href ="mypage.php?page='.$previousPage.'">Previous Page</a> | <a href ="mypage.php?page='.$nextPage.'">Next Page</a>';
}else{
    echo 
'<a href ="mypage.php?page='.$nextPage.'">Next Page</a>';
}

?>
The URL will look like "mypage.php?page=5"
The GET method will read the 5 in the URL as the current page Number: "$pageNum = 5"
I am trying to pass date as parameter to PHP code basically I want to pass every time -7 date

Suppose on 1st click date is 2013-02-10

on 2nd click it will be -7

means 2013-02-3

but problem what is happening is as this is all happening on click of Button, and once the users click on Button the form is posted and again page is REFRESHED and again & again COUNT becomes 0

how can I avoid this is there any global or Static variable concept in Javascript or PHP

Basically I want to Query MySQL when user clicks Previous Previous, as I want to get Weekly Data from Database thats why I am passing Date as Hidden Variable to Query Week by Week Data


PHP Code:
PHP 
<?php

  $day2 
date('Y-m-d');
  
  
$day2    date("Y-m-d",strtotime($day."last Sunday"));

?>


JAVASCRIPT

<script type="text/javascript">
var dateis = '<?php= $day2;?>';
var count =0;
function add()
{

  count ++;    

 if(count >0)
 {
  var prev =  new Date();
  var x=7*count;             

  var newdate = new Date(prev);
  newdate.setDate(newdate.getDate()- x);


  document.getElementById("datesent").value = newdate;
  document.getElementById("getdata").submit();
 }

}

</script>


<form name = "getdata" method ="post" id  = "getdata" action= "getprevdata.php">

<input type = "hidden" id "datesent" name "datesent">

<button onclick="add()"> Previous </button>
</form>
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What do i do ?? Clicked Ad by mistake MeHost AdSense 10 05-09-2012 07:02 PM
How to check if a link has been clicked? JS/PHP AkosBlog Coding Forum 6 08-08-2011 12:53 PM
Blog Tag: I Clicked Your AdSense John Scott Contextual Networks 9 02-01-2007 09:58 PM
Adverts not getting clicked. megamoose Google Forum 3 01-12-2007 06:05 AM
How can I track how many times a .zip file is downloaded? Nick Coding Forum 7 11-07-2006 12:23 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 01:29 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC