Skip navigation
ant01
Currently Being Moderated

List menu using dynamic fields

Jul 26, 2012 7:02 AM

Tags: #list_box #dynamic_list #search_form

Please can someone assist..

 

I am using a dropdown list in a search form that collects the information from a dynamic table.

 

I want the initial entry to be blank but the populated field adds the first entry of the table in the drop down list, how do I remove this and show intial value as blank.

 

I'm also having a propblem with the search results and am not sure of the syntax to use. With the code below the user has to fill in all the search items as I am using AND in the WHERE clause. I have tried OR but this doesn't work. If the field is blank in the search item the results page must ignore it and only use the items selected.

 

Code

 

SELECT wp_dbt_venues.venuesID, wp_dbt_venues.name, wp_dbt_venues.category, wp_dbt_venues.province, wp_dbt_venues.city, wp_dbt_province.provinceID, wp_dbt_province.province, wp_dbt_conferencefacilties.venueid, wp_dbt_conferencefacilties.maxcapacity

FROM ((wp_dbt_venues LEFT OUTER JOIN wp_dbt_province ON wp_dbt_venues.province = wp_dbt_province.provinceID)  LEFT OUTER JOIN wp_dbt_conferencefacilties ON wp_dbt_venues.venuesID = wp_dbt_conferencefacilties.venueid)

WHERE wp_dbt_venues.category = varCat AND wp_dbt_venues.province = varProv AND wp_dbt_conferencefacilties.maxcapacity < varDel

 
Replies
  • Currently Being Moderated
    Jul 26, 2012 10:07 AM   in reply to ant01

    >I want the initial entry to be blank but the populated field adds the first

    >entry of the table in the drop down list, how do I remove this and show intial value as blank.

     

    You create the initial default item first, before looping through the recordset to populate the rest of the values.

     

    >With the code below the user has to fill in all the search items as I am using AND in the WHERE clause.

     

    The best way to handle this is to build your WHERE clause dynamically. That is, evaluate the fields passed from the form and if they are empty, do not include that criteria in the WHERE clause. You will need to code this by hand as DW doesn't handle this scenario.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 12:00 PM   in reply to ant01

    You would be better off building you query in pieces.  I.e.

     

    $and = (isset($_POST['province'])) ? " AND wp_dbt_venues.province = '".$_POST['province']."'" : NULL;

    $and .= (isset($_POST['category'])) ? " AND wp_dbt_venues.category = '".$_POST['category']."'" : NULL;

     

    Then when displaying do this:

     

    <select>

    <option selected></option>

    <?php #loop over results  { ?>

    <option value="id">Whatever</option>

    <?php } ?>

    </select>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points