我有一个应用程序,我想在其中添加一个 AND 按钮,然后创建将 AND 语句添加到查询的选项。这是我现在必须这样做的 php 和 html 代码。问题是我不知道如何将 php 部分连接到 javascript 部分以创建一个添加完全相同代码的按钮?
这是html代码:
这是php代码:
<?php
include "connect.php";
$table = $_POST['tableSelected'];
$field = $_POST['fieldSelected'];
$attribute = $_POST['attributeSelected'];
$operator = $_POST['operatorSelected'];
$fieldList = $_POST['fieldList'];
if (!empty($table)){
if (!empty($fieldList)){
$fieldstr = $fieldList . ",ST_AsGeoJSON(ST_Transform(l.geom,4326),6)";
} else {
$fieldstr = "";
}
$pairs = [];
foreach ($_POST['fieldSelected'] as $key => $field) {
if (!empty($field) && !empty($_POST['operatorSelected'][$key]) && !empty($_POST['attributeSelected'][$key])) {
$pairs[] = $field . " " . $_POST['operatorSelected'][$key] . " '" . $_POST['attributeSelected'][$key] . "'";
}
}
if (count($pairs) > 0) {
$sql .= ' WHERE ' . implode(' AND ', $pairs);
}
//echo ($sql);
?>
这是我目前的html:
<select name="field[]">...</select>
<select name="operator[]">...</select>
<select name="value[]">...</select>