如何在SQL语句中使用jQuery变量?

时间:2015-05-14 18:51:00

标签: php jquery sql variables

myscript.js

$(".tablestyleorchideeaanbod").on("click", function() {
     var value = $(this).find('tr:first td:first').html();
     lastClickedValue = value;
     console.log( value );
     var test = lastClickedValue
});

因此,当我用表tablestyleorchideeaanbod点击我的表时,var test将得到一个值。比方说吧:嗨;

所以,var test = hi

现在我需要在我的主页index.php中使用这个变量。 在index.php中我想使用变量; var test,用于MYSQL查询。

例如:

SELECT * FROM thisismytable WHERE rowname = var test

如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

$(".tablestyleorchideeaanbod").on("click", function() {
     var value = $(this).find('tr:first td:first').html();
     lastClickedValue = value;
     console.log( value );
     var test = lastClickedValue
});

然后你最常使用ajax将数据发送到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'];
// do whatever you want here .....
//insert sql or select
?>