[英]How to use javascript and HTML to add a sql and button?
I have an application where I want to ADD an AND button that, than creates the option to add an AND statement to the query. 我有一个应用程序,要添加一个AND按钮,然后创建将AND语句添加到查询的选项。 This is the php and html code I have to do this at the moment.
这是我目前必须执行的php和html代码。 The problem is I don't know how to connect the php part to the javascript part to create a button that adds exacte the same code?
问题是我不知道如何将php部分连接到javascript部分以创建添加完全相同代码的按钮?
This the html code: 这是html代码:
This is the php code: 这是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);
?>
And this my html at the moment: 这是我目前的html:
<select name="field[]">...</select>
<select name="operator[]">...</select>
<select name="value[]">...</select>
Button click should produce something like it Javascript (jQuery): 单击按钮应产生类似Javascript(jQuery)的内容:
newElement = $("#someSelector").clone(false);
// Some modification of new element. Change id for example
$(newElement).attr("id",newIdValue);
newElement.appendTo("#parentElement");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.