If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Form search - blank fields

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-04, 05:07
elkiwi elkiwi is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Question 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
Reply With Quote
  #2 (permalink)  
Old 09-30-04, 17:55
yellowmarker yellowmarker is offline
Registered User
 
Join Date: Jul 2004
Location: Dundee, Scotland
Posts: 107
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On