For this you would use ajax , using pure javascript or jquery , and add an event sink to that div. However, I do not see much use in doing this with a div , and even more so.
In this example I will use jquery because I do not have the best conditions at my disposal.
$(document).ready(function(){
// mouseover, mouseout, leave
$("#click").on('click', function(){
var rando = 1 + Math.floor(Math.random() * 100); // gerar numeros entre 1 e 100
$.post('upd.php',{status: rando}, function(i){
$("#demo").html('Retorno: ' + i);
});
});
});
This is the part of jquery , I used the click event to avoid complications, and it is also a bit inconvenient to process requests whenever the mouse passes over a div, which will probably always be happening. I commented the event renters.
In requests with ajax you can always choose between $ .post, $ .get, or even $ .ajax .
- $ .post and $ .get (without much configuration);
- $ .ajax (more configuration options, both for get and post ).
For html you would have something like this:
<div id="demo"></div>
<div id="click"></div>
And this to arrange the divs one above the other:
<style type="text/css">
div {display:block;}
#click {width:100%; height:20px; background-color:#204a87; content:"OI";}
</style>
And finally, for the php script you could do something like this:
session_start();
$data = isset($_POST['status']) && !empty($_POST['status']) ? (int) $_POST['status'] : "indefinido\n";
// Restantes verificações para $data...
if(isset($_SESSION['status']) && !empty($_SESSION['status'])){
echo $_SESSION['status'];
} else {
$_SESSION['status'] = $data;
echo $_SESSION['status'];
}
session_destroy();
In this example, I used sessions to illustrate how the values of this variable would change, in case the status values differ from each request. For a query where you have the session variables you would put the SQL query, like this:
$status = isset($_POST['status']) && !empty($_POST['status']) ? (int) $_POST['status'] : "indefinido";
// Restantes verificações para $status...
db::Query("UPDATE bdc SET status='{$status}'");