简体   繁体   中英

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. This is the php and html code I have to do this at the moment. 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?

This the html code:

This is the php code:

<?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:

<select name="field[]">...</select>
<select name="operator[]">...</select>
<select name="value[]">...</select>

This is what I want: 在此处输入图片说明

Button click should produce something like it Javascript (jQuery):

newElement = $("#someSelector").clone(false);
// Some modification of new element. Change id for example
$(newElement).attr("id",newIdValue);
newElement.appendTo("#parentElement");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM