【发布时间】:2015-06-03 03:57:40
【问题描述】:
我编写了一个脚本来发布AJAX 变量,只要单击checkbox。 When multiple checkboxes are selected the variables are stored in an array and seperated by a pipe.我需要将每个变量分别传递到我的 php 函数中,以便我可以运行单独的查询。
我的 JavaScript
$(document).on("change", ".tbl_list", function () {
var tbls = new Array();
$("input:checkbox[name='tbl[]']:checked").each(function () {
tbls.push($(this).val());
});
var tbl = tbls.join('|');
var db = window.sessionStorage.getItem("db");
alert(db);
$.ajax({
type: "POST",
url: "ajax2.php",
data: {
tbl: tbl,
db: db
},
success: function (html) {
console.log(html);
$("#tblField").html(html).show();
}
});
});
选择多个表时的输出
tbl:db|event
我的 PHP 函数
function tblProperties() {
if (isset ( $_POST ['tbl'] )) {
$tbl = $_POST ['tbl'];
$db = $_POST ['db'];
$link = mysqli_connect ( 'localhost', 'root', '', $db );
$qry = "DESCRIBE $tbl";
$result = mysqli_query ( $link, $qry );
我知道我需要以某种方式存储这些变量,然后执行 for each 以生成单独的查询,但我不知道该怎么做。
【问题讨论】:
-
你不能
explode('|', $tbl);有一个数组然后做foreach($array as $tbl) { }吗? -
为什么不在php中使用
explode -
用w3schools.com/php/func_string_explode.asp爆破PHP中的变量tbl怎么样
标签: javascript php jquery ajax post