php - How to use jQuery variable in SQL statement? -
myscript.js
$(".tablestyleorchideeaanbod").on("click", function() { var value = $(this).find('tr:first td:first').html(); lastclickedvalue = value; console.log( value ); var test = lastclickedvalue });
so when got clicked on table class tablestyleorchideeaanbod, var test value. let's example: hi;
so, var test = hi
now need use variable in homepage, index.php. in index.php want use variable; var test, use in mysql query.
for example:
select * thisismytable rowname = var test
how achieve this?
$(".tablestyleorchideeaanbod").on("click", function() { var value = $(this).find('tr:first td:first').html(); lastclickedvalue = value; console.log( value ); var test = lastclickedvalue });
then use ajax send data de server
$(".tablestyleorchideeaanbod").on("click", function() { var value = $(this).find('tr:first td:first').html(); lastclickedvalue = value; console.log( value ); var test = lastclickedvalue; $.ajax({ url: 'data.php', type: "post", /*contenttype: "application/json; charset=utf-8",*/ data: {val : test }, datatype: 'json', success: function (data) { console.log(data); } }); });
php script data.php
<?php $val = $_post['val']; // whatever want here ..... //insert sql or select ?>
Comments
Post a Comment