Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Question Unanswered: Form search - blank fields

    Hi, I'm trying to set up a search of my database from a form which when submitted sends 3 fields as variables to a results page with the POST method.

    My question is what do I need in the query to display all records in a column if that field was left blank in the form ie if 'area' was not specified, display all areas...

    At the moment blank field display no records.

    $colRooms_RSmaster = "%";
    if (isset($HTTP_POST_VARS['ROOMS'])) {
    $colRooms_RSmaster = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['ROOMS'] : addslashes($HTTP_POST_VARS['ROOMS']);
    $colType_RSmaster = "%";
    if (isset($HTTP_POST_VARS['TYPE'])) {
    $colType_RSmaster = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['TYPE'] : addslashes($HTTP_POST_VARS['TYPE']);
    $colArea_RSmaster = "%";
    if (isset($HTTP_POST_VARS['AREA'])) {
    $colArea_RSmaster = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['AREA'] : addslashes($HTTP_POST_VARS['AREA']);
    mysql_select_db($database_connIH, $connIH);
    $query_RSmaster = sprintf("SELECT * FROM properties LEFT JOIN type ON (properties.type = type.typeid) WHERE type = '%s' AND rooms = '%s' AND zone LIKE '%%%s%%'", $colType_RSmaster,$colRooms_RSmaster,$colArea_RSma ster);
    $query_limit_RSmaster = sprintf("%s LIMIT %d, %d", $query_RSmaster, $startRow_RSmaster, $maxRows_RSmaster);
    $RSmaster = mysql_query($query_limit_RSmaster, $connIH) or die(mysql_error());
    $row_RSmaster = mysql_fetch_assoc($RSmaster);

    Thanks for any help. Sorry about DW code.

    El Kiwi

  2. #2
    Join Date
    Jul 2004
    Dundee, Scotland
    dynamically build the sql query using if statements so that only the search fields that were input by the user are used in the sql query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts