duandong7980 2016-06-23 11:28
浏览 95

如何使用javascript和HTML添加sql和按钮?

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: enter image description here

  • 写回答

1条回答 默认 最新

  • dongzhan5286 2016-06-23 12:00
    关注

    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");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作