I am trying to create a kind of request where registered members see posts of other registered members. They might choose to connect with them before they can be able to comment on the post. What I want is to use jQuery to send the request to PHP which in turn inserts into the database with a status connection requested. When the member sees the request he can then choose to accept or reject that request. If he accepts it, the status will change to you are connected with this member.
Please I know that there are similar questions like this but not exactly as mine, somebody should please help.
'cont_email' is email of member sending request
'email_cont' is email receiving the request
'status' is the status of the connection
'counter' is request increment
This is my HTML part:
<input name="connect" type="button" value="Connect with <?php echo"$mem_com[name]";?>" class="intag2" onclick="connt()"/>
The PHP part is working ok. My only problem is sending the request through jQuery to PHP and back to jQuery which now displays the status of the connection based on members activity.
Updated answer:
Put this content into the file the user's will see (I assume thet the get parameters will be passed to this page when the user lands on them?):
<input id="connectButton" name="connect" type="button" value="<?php echo $status;?>" class="intag2" />
<script type="text/javascript">
var email_cont = '<?=$_GET[email_cont]?>';
var cont_email = '<?=$_GET[email]?>';
$('#connectButton').click(function() { // add a click event to the button (no need for onclick)
var counter = 0;
$.ajax({
url: 'requests.php?cont_email='+cont_email+'&email_cont='+email_cont+'&counter='+counter,
success: function( data ) {
$('#connectButton').val(data); // set the button value to the new status.
$('#connectButton').unbind('click'); //stop the user clicking the button loads of times.
}
});
});
</script>
Then put this in a file called requests.php:
<?php
$email_cont = $_GET['email_cont'];
$cont_email = $_GET['cont_email'];
$counter = $_GET['counter'];
$status = "Connection Sent!";
$insert = mysql_query("INSERT INTO request VALUES ('','$cont_email','$email_cont','$status', '$counter', NOW())");
$result = mysql_query($query);
if(!result){
//If it fails to run the SQL return an error.
echo "Connection Failed!";
}else{
//If all goes well, return the status
echo $status;
}
?>
Not tested, but should do what you are looking for.
Related
I am making a check to see if the user account is freeze, this is in my database, $r is where I am getting the user data (name, freeze account, etc).
So if the freeze account is set to be 0 then I am showing a unchecked box otherwise a checked box. It works fine, however my question is how could I save it if I checked the box to say that the user account is freeze.
I know how to write the query if they check the box to say that the user account is freeze, just calling this function :
function updatefreezeaccount(){
mysql_query("UPDATE `users` SET `freeze_account` = 1 WHERE `user_id` = '$user_id'");
}
This is my code so far :
<?php
if ($r['freeze_account'] == 0) {
echo '<div class="example">
<input type="checkbox" unchecked data-toggle="toggle">
</div>';
}
else {
echo '<div class="example">
<input type="checkbox" checked data-toggle="toggle">
</div>';
}
?>
I don't have a form, so I want to know if I can do it without having a form
However I don't know how to make the check to see if the user has checked the box or not, any suggestion would be appreciated, thanks
POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
//here you need to call the page where your update query has
var user_id = "<?php echo $user_id;?>"; //if $user id present in the same page
$.post("your_page.php", {user_id : user_id}, function(feedback){
alert(feedback);// the feedback is come form the `your_page.php`, what you want to return
});
}
else if($(this).prop("checked") == false){
alert("Checkbox is unchecked.");
}
});
});
You can also pass your user_id as an attribute of the checkbox.
You will need javascript to do this. If you are using jquery, then you can do simply $(selector).on('click', function(){ Call to server side }); or you can go vanilla js and do something like <button onclick="myFunction()">Click me</button> and write a js function do the server side call.
You want to use JavaScript and a framework, like jQuery. This is a front end issue, not a backend issue.
So something like this would work.
$('#the-checkbox').click(function() {
if ($(this).is(':checked')) {
$.post('to-your-form', {client_id: 'client_id', 'freeze':'1'}, function(response) {
console.log(response);
});
} else {
$.post('to-your-form', {client_id: 'client_id', 'freeze':'0'}, function(response) {
console.log(response);
});
}
});
I have a database table which I am trying to retrieve data from using JQUERY AJAX. When my first page loads it does a php call to a table and populates a select form element. - This works
I then want to select one of the options submit the form and have the row returned via Ajax.
Previously I had the script working with just PHP files but am having trouble getting it to work. When submitting the form my URL is changing:
http://localhost/FINTAN/testertester.php?name=Specifics.
I am not getting anything back. In addition when looking at my console I get a jquery not defined
factory (jquery). I can find the line in question in my jquery ui.js. Not sure if this is the issue or my code has caused the issue. I have cleard the firefox cache and due to the fact I have not had a successful AJAX call via jquery method am guessing it my code.
To get the code below I have mixed and matched a book and an online tutorial and many other sources and this is not my first attempt. Ideally I would like to output table row. However just getting a request working and knowing its not a conflict or compatability issue would makeme feel better and not hindered before I start
<script src="jquery/jquery-ui-1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
var vname = $("#name").val;
}
}
$.post("addithandle1.php",
{
name:vname};
function(response,status){
alert("recieved data-------*\n\nResponse : " + response
+"\n\nStatus : " + status);
}
}
</script>
</head>
<body>
<?php
include "config.php";
if (mysqli_connect_errno($con))
{
}
else
{
$result = mysqli_query($con, "SELECT * FROM script ");
echo " <Form method='post'> <label>Script :</label> <select id='name' name='name' >";
}
while($row = mysqli_fetch_array($result))
{
echo "<option value = '".$row['scriptname']."'>".$row['scriptname']."</option>";
}
echo "</select>";
echo "<button id='btn' class='btn-search'>Load Script </button></form>";
?>
</body></html>
This is my PHP file that I am trying to retrieve from
<?php
include 'config.php';
$batchtype2 = $_POST['name'];
$batchtype2 = mysqli_real_escape_string($con,$batchtype2);
$sql = "SELECT * FROM script WHERE scriptname = '".$batchtype2."' ";
$result = mysqli_query($con,$sql);
$count=mysqli_num_rows($result);
if($count==0 ){
echo "</br></br></br></br></br></br></br><p> No Matching results found</p>";
}
else{
while($row = mysqli_fetch_array($result)) {
echo '<tr><td>'.$row['scriptname'].'</td></tr>';
echo '<tr><td>'.$row['scripthours'].'</td></tr>';
echo '<tr><td>'.$row['scripttotal'].'</td></tr>';
}
}
mysqli_close($con);
?>
Thanks in advance for any help
By making the following corrections (you have some syntax issues as well as usage issues which should be revealed in your browser's console when you load this page) in your JavaScript/jQuery this will work like you expect -
Make sure to change this line -
var vname = $("#name").val;
to this -
var vname = $("#name").val(); // note the parentheses
in your function -
$(document).ready(function(){
$("#btn").click(function(e){
e.preventDefault(); // prevent the default action of the click
var vname = $("#name").val();
$.post("addithandle1.php", {name:vname}, function(response, status) { // POST instead of GET
// never use alert() for troubleshooting
// output for AJAX must be in the callback for the AJAX function
console.log("recieved data-------*\n\nResponse : " + response +"\n\nStatus : " + status);
$('#table').html(response); // put response in div
});
});
});
Now $_POST['name'] should get populated properly.
To get the table to appear in your requesting page first make sure that your PHP forms the table completely.
Add a div to your requesting page and modify the AJAX call above as shown.
<div id="table"></div>
Now, when you make a request the div on the requesting page will be updated with whatever comes back from the PHP script.
There are a couple of things about your script.
First make sure you write well structured code and that it is nothing in the wrongplace / broken.
You have in the $(document).ready(function(){ only the .click event of the button, but you left the ajax request outside, I imagine you did that so it will also make the ajax request in the first page load
The problem is that now it will only make it in the first page load, but not when you click the button, on clicking button you are only getting the value of name.
I recommend you to try something like this:
<script>
$(document).ready(function() {
// bind button click and load data
$("#btn").click(function(){
loadData();
return false; // prevent browser behaviour of the button that would submit the form
}
// load data for the first time
loadData();
};
function loadData() {
var vname = $("#name").val;
$.post("addithandle1.php", { name:vname }, function(response, status) {
alert("recieved data-------*\n\nResponse : " + response
+"\n\nStatus : " + status);
});
}
</script>
A few notes:
I would recommend always putting jquery code inside $(document).ready since that guarantees that jquery was loaded before running it
By default a form that has a submit button that you click, will get the form submitted by the browser, if you use ajax, you should prevent that behaviour, either on the button click event or on form with onsubmit="return false".
I'll start with what I'm trying to do.
I've created a "Forgotten Password" system where the user enters their email address and (if correct) they will be sent an email with a reset link.
There is a small section of ajax in the form page which detects if the email entered is in the database. If the email does exist in the database the form changes color to green and the submit button is enabled. If the email is not detected the form stays red and the submit button is disabled.
The issue is that when typing the email address, the keyup event seems to happen when the user has entered one more character than the correct email (basically if hello#123.com was in my database, they would have to enter hello#123.com1 for submit to be enabled)
Here is my JSFiddle with everything apart from the ajax working.
Here is an example of the ajax file itself:
<?php
session_start();
$Email = $_POST['email'];
//Parse ini file containing database information
$databaseInfo = parse_ini_file("optiMizeWebReport.ini", true);
global $con;
//Connect to database
$con = #mysqli_connect($databaseInfo['optiMizeDatabaseConnection'] ['WebServer'],$databaseInfo['optiMizeDatabaseConnection']['Username'], $databaseInfo['optiMizeDatabaseConnection']['Password'], $databaseInfo['optiMizeDatabaseConnection']['DBName']);
//Check connection and output error if invalid
if(!$con)
{
die('Connect Error ('. mysqli_connect_errno() .') '.mysqli_connect_error());
}
//Execute query
$result = mysqli_query($con, "SELECT COUNT(*) FROM login WHERE Email='$Email'")
or die("Error: ".mysqli_error($con));
//Initialize
$emailMatch = array();
//Extract
while($emailMatch[] = mysqli_fetch_array($result))
print_r($emailMatch[0][0]);
?>
If there is any other information i can give that will help please let me know. Thanks.
EDIT:
As there still seems to be no quick fix/answer I've made a short video showing exactly what happens. You can see it here: https://www.youtube.com/watch?v=P-2Gz5b4ek8
Ajax requests are asynchronous! In your case when you check if(databaseCheck != 1) the value of databaseCheck is previous ajax's response. Thats why you have to type 1 extra character to get last result.
$('input').bind("keyup", function() {
$.ajax({
type: "POST",
url: "ForgotPasswordAjax.php",
data: {email: $('#email').val()},
success: function(output){
console.log(output);
notification(output);
}
});
});
function notification(databaseCheck) {
if (databaseCheck != 1) {
....
} else {
....
}
}
on success part call a function like this, it will ensure that these codes will run after ajax success.
It will solve your current issue but you have to prevent simultaneous ajax calls. We have no idea which request return first, if first request response last js will set notification with that response. So you have to add a processing flag to prevent it.
i have updated the JsFiddle.
Here i have included keydown and focus into
$('#email').bind("keyup keydown change focus blur", function() {
and change below line
$('input').bind("keydown", function() {
jQuery has another event called input.
$('#email').bind("input", function() {
updated jsFiddle
i really do hope to get a helpful answer. i've been working on a way to make a chatbox that allows private sessions between two users,one where only two users chat with the option of joining the general chatroom, i'm doing this without any xmpp,sockets etc, i'm just using files which would serve as logs, i'll explain the concept:
a user has logged in, they are directed to the chat-page, where a list of their friends stored in a database is loaded to their right, this part is working fine:
//i've declared all the variables previously
//skip to the part that loads the names:
while($rowb=mysql_fetch_array($done))
{
$rafiki=$rowb['name'];
//show the names,when the user clicks on any of them, the name(variable $jina) of the user
//and the friend's name are sent to the function makefile()
echo "<a href='Javascript:makefile(".$jina.",".$rafiki.")'>"."$rafiki"."</a>"."<br/>";
}
when the user clicks on any name, they are sent to the javascript function, which takes both parameters, the user's name and the name of the friend, and then adds an extension at the end, to make a log file that would serve as the chat log between both of them:
function makefile(username,friendname)
{
//add file extension
var ext=".html";
//concatenate
var dash="-";
var full=username.concat(dash,friendname,dash,ext);
var str=friendname.concat(dash,username,dash,ext);
so each pair would have their own file, the variable full is sent to a script via ajax to make the process seamless, the script does a number of things:
it first checks to see if a log file, that bears the data sent from the client side exists, either beginning with the user's name or the friend's name,if either file exists,it checks to see if any messages have been sent and writes them to the file, if neither file exists, it creates a new file,and prompts a user that a friend wants to start a chat, when the friend clicks on the user's name, the first condition will succeed, because a file would already have been made:
<?php
session_start();
$full=$_POST['full'];
//first, check to see if variations of the file already exist
//start by exploding the sent data
$result=explode("-",$full);
$usrnme=$result[0];
$frndnme=$result[1];
$ext=$result[2];
//make varied names for comparison
$vrdfull=array($result[1],$result[0],$result[2]);
$str=implode("-",$vrdfull);
$_SESSION['str']=$str;
$_SESSION['full']=$full;
//start actual comparison
if(file_exists($full)||file_exists($str))
{
//stuff to do if first file exists
if(file_exists($full))
{
//check to see if message has been sent
if (isset($_POST['message']))
{
$message=$_POST['message'];
//update existing file with message
$fp=fopen($full,'a');
fwrite($fp, "<div id=\"sent\">".$usrnme." :"." ".$message."<br/>"."</div>");
//close the file
fclose($fp);
}
}
else
//stuff to do if second file exists
{if(file_exists($str))
{
//check to see if message has been sent
if (isset($_POST['message']))
{
$message=$_POST['message'];
//update existing file with message
$fpp=fopen($str,'a');
fwrite($fpp, "<div id=\"sent\">".$usrname." :"." ".$message."<br/>"."</div>");
//close the file
fclose($fpp);
}
}
}
}
else
{
//create file, since neither files exist
$fhandel=fopen($full,'a');
//check if message has been sent
if(isset($_POST['message']))
{
$messssage=$_POST['message'];
fwrite($fhandel,"<div id=\"sent\">".$usrname." "." : ".$messssage."<br/>"."</div>");
}
fclose($fhandel);
//send msg to friend, incurring them to accept
$ext=".html";
$frrnme=$frndnme.$ext;
$fpp=fopen($frrnme,'a');
//prompt the user to initiate chat by opening file,by clicking on the name he/she would see
fwrite($fpp,"<div id=\"msg\">".$frndnme." wants to chat, click on their name to accept"."</div>");
fclose($fpp);
}
?>
i don't think this part has any problems, just posted it to help convey the idea across.here's the ajax that sends the string full to the script (i think it may be wrong):
$.ajax({
type:'POST',
url:'makesend.php',
data: {full:full},
//what to do if data was sent:
success: function(full){
$('#myResponse').html(full);
}
});
return false;
no data is shown in the div "myresponse", so i think there's a problem here, i don't know what. the next thing would be to handle messages sent by the users,here's the form that would get their input:
<form name="message" action="">
<input name="message" type="text" id="usermsg" size="63" />
<input name="submitmsg" type="submit" onclick="send()" id="submitmsg" value="Send" />
</form>
and here's the function send() that sends data to the makesend.php file:
function send(){
var clientmsg = $("#usermsg").val();
$.post("makesend.php", {message: clientmsg});
$("#usermsg").attr("value", "");
return false;
}
again, when i tested this and wrote a message, the page reloaded and no data was sent to the script! there's a problem here as well,i don't know what it is. moving on, after the file has been created and the user's begin interaction, it needs to be uploaded to a message area where the user can see it, here's the message area div:
remember that i'll need to load a file that exists, so before loading it to this area, i'll need to use php to see which version exists, either one with the user's name first or with the friend's name (either $full or $str):
$("#msgarea").html(
"<?php
//check to see if either file exists
if(file_exists($_SESSION['full'])||file_exists($_SESSION['str'])){
//check to see if the first file exists:
if(file_exists($_SESSION['full']))
{
$full=$_SESSION['full'];
$handlle = fopen($full, "r");
$contents = fread($handlle, filesize($full));
fclose($handlle);
//load it's contents to the division if it does
echo $contents;}
else
{
//if first file doesn't exist, load the second one:
$str=$_SESSION['str'];
//check to see if it exists before loading it
if(file_exists($str))
{
$handle = fopen($str, 'r');
$contents = fread($handle, filesize($str));
fclose($handle);
//load it to the division
echo $contents;
}
}
}
?>"
);
i think it's legal to do that, add php code to the innerHTML of an element, so this code would load whatever version of the file that exists. i get the file names from the session because this part of the code gets executed after data is sent to the makesend.php file, which starts a session and gives them ($_SESSION['full'] and $_SESSION['str']) values. this part that loads the file is the last piece of code within the function makefile(), first, the function obtains data from the user in form of the name they clicked, it sends them to a script (makesend.php) which creates the chat log file, after this, comes the last part, which loads the data onto the division "msgarea". next, i'd need to refresh/reload the created log file after a certain amount of time to show the messages sent by the users, i chose to use 2.5 seconds, this part is outside the function makefile(),i had to use php within the jquery to first check which file exists, i'd then use jquery in the php to reload and animate(auto-scroll) the existing one,this php is inside the 'javascript' tags:
<?php
//set up the conditions
$full=$_SESSION['full'];
$str=$_SESSION['str'];
//check whether either file exists
if(file_exists($full)||file_exists($str))
{
//reload the first file if it exists
if(file_exists($full)){
//this is the jquery inside the php(which is also in javascript tags)
echo '<script type="text/javascript" src="jquery-1.8.0.min (1).js"></script>';
echo '<script type="text/javascript">';
echo
'function loadLog(){
var oldscrollHeight = $("#msgarea").attr("scrollHeight") - 20;
$.ajax({
url: <?php session_start(); echo $_SESSION[\'full\']?>,
cache: false,
success: function(html){
$("#msgarea").html(html); //Insert chat log into the #msgarea div
var newscrollHeight = $("#msgarea").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#msgarea").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
}
},
});
}
setInterval (loadLog, 2500); //Reload file every 2.5 seconds';
}
else{
//this will reload the second file since the first doesn't exist:
echo
'function lloadLog(){
var oldscrollHeight = $("#msgarea").attr("scrollHeight") - 20;
$.ajax({
url: <?php session_start(); echo $_SESSION[\'str\']?>,
cache: false,
success: function(html){
$("#msgarea").html(html); //Insert chat log into the #msgarea div
var newscrollHeight = $("#msgarea").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#msgarea").animate({ scrollTop: newscrollHeight }, \'normal\'); //Autoscroll to bottom of div
}
},
});
}
setInterval (lloadLog, 2500); //Reload file every 2.5 secsonds';
}
echo '</script>';
}
?>
and i think that's it, the entire system, also, there's a problem with the logout call, here's the code, it's at the very end of the file:
$("#exit").click(function(){
var exit = confirm("Are you sure you want to end the session?");
if(exit==true){window.location = 'testing.php?logout=true';}
});
here's the markup for it:
<p class="logout"><a id="exit" href="#">Exit Chat</a></p>
and at the top of the file, here's the part that checks whether it's set to true:
session_start();
//logout function
if(isset($_GET['logout']))
{
if(file_exists($_SESSION['full'])||file_exists($_SESSION['str']))
{
if(file_exists($_SESSION['full']))
{
$full=$_SESSION['full'];
$flogout=fopen($full,'a');
fwrite($flogout, $_SESSION['username']." has left the anichat!!! "."<br>");
fclose($flogout);
}
else
{
$str=$_SESSION['str'];
if(file_exists($str))
{
$flogoout=fopen($str,'a');
fwrite($flogoout, $_SESSION['username']." has left the chat "."<br>");
fclose($flogoout);
}
}
}
session_destroy();
header("Location:testing.php");//user redircect.
}
the user's page is not even refreshed so that the session is destroyed, it just refreshes and the session data is still present(this is because the login form isn't shown, it's supposed to be shown if the $_SESSION['name'] is empty). i know that this is a long question, but i am a beginner and i really need help with this, i think the main issues are with the ajax, but if you can spot anything else i will be very thankful, i kindly ask for a relevant answer that will help me implement this, if you would like me to post the entire code present in both testing.php and makesend.php,in a way that is not separated like the way i've done here to illustrate, please ask if it helps.i thank all you advanced programmers who go out of their way to help others, thanks in advance.
I guess it is that the processing page makesend.php is no retrieving anything to the request. You can use firebug to determine if it is writtin some thing. I am saying it since you are not reading the file after you updated (didn't see it) You can create a new ajax request that is called periodically after some interval and load the contents in the log file with the conversation.
The attached picture shows the results page of the search engine that I'm building. For each return result, the user may click on the result (i.e. "Food Science") and it will expand out accordion-style to reveal information about that particular result.
I want to log each time the user clicks on a result (for learning/intelligence purposes) and store it in a database table that I have created which stores the session ID, the query, the position of the result, and the order in which the user clicked the item.
Using JQuery, I already have a function that will pull the title of the result that was clicked, and I have it set where I want to log the click, but I don't know how to do it since JQuery is client side and PHP is server side.
How can I use the JQuery to trigger a PHP function so that I can query the database to insert the click logs into my table?
Below is the JQuery function.
$(document).ready(function() {
$('.accordionButton').click(function(e) {
if($(this).next().is(':hidden') == true) {
$(this).addClass('on');
$(this).next().slideDown('normal');
$(this).next().slideDown(test_accordion);
// SEND CLICK ACTION TO LOG INTO THE DATABASE
alert($(this).find('h3:last').text()); // displays the title of the result that was just clicked
}
else {
$(this).removeClass('on');
$(this).next().slideUp('normal');
$(this).next().slideUp(test_accordion);
}
});
}
You can do something like this (untested):
Define a javascript variable to track the order of the clicks, outside your click function:
var order = 0;
Add this into your click function, at the bottom:
order++;
var sessionID = $("input[name='sessionID']").val(); // assuming you have sessionID as the value of a hidden input
var query = $("#query").text(); // if 'query' is the id of your searchbox
var pos = $(this).index() + 1; // might have to modify this to get correct index
$.post("logClick.php", {sessionID:sessionID, query:query, pos:pos, order:order});
In your php script called "logClick.php" (in the same directory):
<?php
// GET AJAX POSTED DATA
$str_sessionID = empty($_POST["sessionID"]) ? '' ; $_POST["sessionID"];
$str_query = empty($_POST["query"]) ? '' ; $_POST["query"];
$int_pos = empty($_POST["pos"]) ? 1 ; (int)$_POST["pos"];
$int_order = empty($_POST["order"]) ? 1 ; (int)$_POST["order"];
// CONNECT TO DATABASE
if ($str_sessionID && $str_query) {
require_once "dbconnect.php"; // include the commands used to connect to your database. Should define a variable $con as the mysql connection
// INSERT INTO MYSQL DATABASE TABLE CALLED 'click_logs'
$sql_query = "INSERT INTO click_logs (sessionID, query, pos, order) VALUES ('$str_sessionID', '$str_query', $int_pos, $int_order)";
$res = mysql_query($sql_query, $con);
if (!$res) die('Could not connect: ' . mysql_error());
else echo "Click was logged.";
}
else echo "No data found to log!";
?>
You can add a callback function as a third parameter for the $.post() ajax method if you want to see if errors occured in the script:
$.post("logClick.php", {sessionID:sessionID, query:query, pos:pos, order:order},
function(result) {
$('#result').html(result); // display script output into a div with id='result'
// or just alert(result);
})
);
EDIT: If you need the value of the order variable to persist between page loads because you paginated your results, then you can pas the value of this variable between pages using either GET or POST. You can then save the value in a hidden input and easily read it with jQuery. (Or you could also use cookies).
Example (put this in every results page):
<?php
$order = empty($_POST["order"]) ? $_POST["order"] : "0";
$html="<form id='form_session' action='' name='form_session' method='POST'>
<input type='hidden' name='order' value='$order'>
</form>\n";
echo $html;
?>
In your jQuery, just change var order = 0; to
var order = $("input[name='order']").val();
Then, when a user clicks on a page link, prevent the default link action, set the order value and the form action, and then submit the form using javascript/jQuery:
$("a.next_page").click(function(event) {
event.preventDefault();
var url = $(this).attr("href");
$("input[name='order']").val(order);
$("#form_session").attr('action', url).submit();
});
All the 'next' and 'previous' pagination links must be given the same class (namely 'next_page' (in this example).
EDIT: If your pagination is as follows:
<div class='pagination'>
<ul><li><a href='page1.url'>1</a></li>
<li><a href='page2.url'>2</a></li>
</ul>
</div>
then just change this:
$("div.pagination a").click(function(event) {
etc.
This one is pretty easy, you need a PHP-Script to handle AJAX requests which are sent from your Search page.
In your search page you'll need to add an .ajax to create an AJAX request to your Script.
Everything you need to know about AJAX can be found here: http://api.jquery.com/jQuery.ajax/
In your PHP-Script you'll handle the Database action, use GET or POST data to give the script an ID over Ajax.
Use Ajax. Write a simple php-script that writes clickes to the database. I don't know how you log the clicks in the database exactly, but you can send the clicked item unique identifier to a php script with ajax, for example via POST variables.
A little example, on click:
$.post(
'count_click.php',
{ id: "someid" },
function(data) {
// data = everything the php-script prints out
});
Php:
if (isset($_POST['id'])) {
// add a click in the database with this id
}
Send a request to a PHP page using jQuery AJAX. See here for more info (it is really simple):
http://api.jquery.com/jQuery.ajax/
In this particular case, as you do not need to return anything, it may be better to just use the POST or GET methods in jQuery:
http://api.jquery.com/jQuery.post/
http://api.jquery.com/jQuery.get/
Something like:
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston"
success: function(data){
alert('done');
});