Search query coming from a Dynamic form (Codeigniter)

Asked

Viewed 279 times

1

I have a problem to build 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), or whenever a new field is added it must be possible to search for this field, someone can give me a light on how to do it?

Thank you

  • 1

    explains one thing to me, how is it that these fields are added in the research part?

  • through another form, in another section of the website

1 answer

1

Orange, could you explain your situation better?

From what I understand, you have a single screen application and in this there are Textbox and Combobox fields, and you need to create a query to the database with these fields, when these are filled, this is it?

If yes, a simple idea.

Use an if to identify which Text or Combo has been filled or selected and fill in the field TAG with the table column name. 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 + "," );

        }
    }
  • Luiz thanks for the tip, but wanted a solution to php (codeigniter framework), however I have a screen with several checkbox and several text boxes, but these fields today can be 10 tomorrow can be 100 and with different names, that is I need the query to be mounted dynamically so that whenever there is a new field the query is done with this field, the part of the validations if a field is filled or not I already solved and I can pick up the text boxes by the id of each, but when it comes to mounting the query I am not able to codeigniter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.