Seems simple enough. I'm creating a search engine that returns results to the user in paginated fashion. Each result is displayed in a list, and if the user clicks on any particular result, it expands out accordion-style and shows them some more information.
I'd like to implement some learning in my search rankings, so I'm going to be tracking which results the user clicks on, and the order in which they're clicked.
I can already track clicks on one page. Each time the user clicks on a result, it is stored in a database with all the information I need.
Here's my problem: If the user goes to the next page of results, I lose the current click count. I'm counting the clicks using jQuery - each time the user clicks a result, the click count increases, and the result, the result's actual rank in the list, and the current click count is added to the database as a single row.
So how can I hold onto the click count?
Here's my click function, where js/clicklog.php is where the query is sent to the database:
var order = 0;
$(document).ready(function() {
alert(order);
$('.accordionButton').click(function(e) {
if($(this).next().is(':hidden') == true) {
$(this).addClass('on');
$(this).next().slideDown('normal');
$(this).next().slideDown(test_accordion);
order++;
var actualOrder = $(this).find("h3").eq(0).text();
var major = $(this).find("h3").eq(2).text();
var sessionID = $("#sessionID").text();
$.post("js/clicklog.php", {sessionID:sessionID, major:major, actualOrder:actualOrder, order:order});
}
The sessionID is being pulled from a hidden div on the page, which is set from $_SESSION['id']. I imagine I could maybe do something similar for the click count?
I understand WHY it's not working, but I just can't think of a solution of how to fix it since I'm still pretty new to jQuery, PHP, and AJAX.
If necessary, please let me know if there is any other code that you wish for me to post.
You could put it into a PHP session variable
<?php
session_start();
if(isset($_SESSION['views']))
{
$_SESSION['views']=$_SESSION['views']+1;
}
else
{
$_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
}
?>
You could probably send to the clicklog.php file where you would have the session variable and increment it and then return it how you are returning sessionID
update from comment What you need to do is send a ajax request in your jquery
var count = 2;
$.ajax({
type: "GET",
url: "some.php",
data: ({'count' : count}),
success: function(msg){
alert( "Data Saved: " + msg );
}
});
Then receive it via post method or get if you choose that way instead and then process adding 1 to variable and returning it. hint whatever the php echos becomes msg.