mardi 28 juin 2016

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

Aucun commentaire:

Enregistrer un commentaire