jonathan-dunstans
asked on
Jquery and PHP
I am working on an update of our recruitment site as am looking into using a dropdown to allow the user to access the content. I have gotten the drop down working fine I just can't work out a way to get the usage stats that we currently have from when users view an advert.
How can I get a one added to the correct entry when a user clicks through? I am using jquery and php with a mysql database.
For example a user clicks on our top job ad the content unfurls below the job title and a click is registered in our database to show that someone has viewed it.
For all I know this could be done solely with javascript but my jscript knowledge is in its infancy.
How can I get a one added to the correct entry when a user clicks through? I am using jquery and php with a mysql database.
For example a user clicks on our top job ad the content unfurls below the job title and a click is registered in our database to show that someone has viewed it.
For all I know this could be done solely with javascript but my jscript knowledge is in its infancy.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$('#linkbox').hide();
$('a.linka').click(function() {
var id = $(this).attr('id');
$('#linkbox' + id).toggle(500);
// alert(id);
return false;
});
});
</script>
<div class="linkbar"><a href="'.$reclist['jobID'].'" id="'.$reclist['jobID'].'" class="linka" name="'.$reclist['jobID'].'" style="color:#BA3F3F">'.$reclist['jobTitle'].'</a></div>
'.$reclist['company'].'
</td>
<td>
'.$reclist['location'].'
</td>
<td>
'.$reclist['deadline'].'
</td>
<td>';
if (!empty($reclist['logo'])) { echo '<img src="mysite/images/recruitment/logos/'.$reclist['logo'].'"'; if($width > 150){ echo ' width="150">'; }else{ echo 'height="70">'; }} echo'
</td>
</tr>
<tr>
<td colspan="4">
<div id="linkbox'.$reclist['jobID'].'" class="linkbox" style="display:none">
'.$reclist['description'].'
</div>
Hi,
You could add in the javascript click function a jQuery ajax call to a php script on your server, pass that script the job number and all that script needs to do is increment a field in your database tracking the clicks and return back an xml document stating success or failure of the query.
You could add in the javascript click function a jQuery ajax call to a php script on your server, pass that script the job number and all that script needs to do is increment a field in your database tracking the clicks and return back an xml document stating success or failure of the query.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This almost gets me there but I need a way for it to only record opens, it currently adds one if I am closing the area as well. So is there some kind of function for only doing on show?
Open your page via the browser, Look at the source code, then copy it and paste it here.
ASKER
The following did the business. Thanks for getting me the first step of the way.
$('document').ready(function(){
$('#linkbox').hide();
$('a.linka').toggle(function() {
var id = $(this).attr('id');
$('#linkbox' + id).show(500);
$.post('clickrecorder.php', {"productID": encodeURIComponent(id)} );
}, function() {
var id = $(this).attr('id');
$('#linkbox' + id).hide(500);
});
});
ASKER
Needed a bit of alteration but worked very nicely. Thanks.
<img src="my.jpg" />
You might have one that looked like this:
<img src="update_script.php?job
The use of jQuery may actually complicate this a bit - you would not want to pre-load the image into a hidden DIV, you would want to load it only after there was a click on the link to view the job.