Search Query from a Dynamic Form (Codeigniter)

1

I'm having a problem building a QUERY that comes from a dynamic form.

I have a search form in which the fields for search are dynamic (can be text or checkbox), that is, whenever a new field is added it must be possible to search for that field, someone can give me a light how to do it?

Thank you

    
asked by anonymous 10.11.2015 / 12:47

1 answer

1

Orange, could you explain your situation better?

So I understand, you have a single-screen application and in this there are TextBox and ComboBox fields, and you need to create a query of the bank query with those fields, when those fields are filled,

If so, a simple idea.

Use an if to identify which Text or Combo has been filled or selected and fill in the TAG of the fields with the name of the columns of the table. Ex:

private void DefineNomeCampos()
    {
        comboBox1.Tag = "COL_TIPOPESSOA";
        textBox1.Tag = "COL_NOMEPESSOA";

    }
    private void PreencheQuery()
    {
        StringBuilder sbSelect = new StringBuilder();
        StringBuilder sbWhere = new StringBuilder();

        sbSelect.Append("Select ");
        if (!string.IsNullOrEmpty(textBox1.Text))
        {
            sbSelect.Append(textBox1.Tag + ",");
            sbWhere.Append(textBox1.Tag + "=" + textBox1.Text + ",");

        }
        if (Convert.ToInt32(comboBox1.SelectedValue) != -1)
        {
            sbSelect.Append(comboBox1.Tag + ",");
            sbSelect.Append(comboBox1.Tag + "," + comboBox1.SelectedText + "," );

        }
    }
    
10.11.2015 / 13:26