![]() |
![]() |
||||||
|
|||||||
| Tags: issue, sql |
![]() |
|
|||
|
I have a problem with my SQL, it will return values if I submit nothing into my
searchbox or it will find one matching value and display results for that, I would like a match for exact search values, mainly on price. Also is there a way I can dynamically display a drop down box with different values to the one I already have? // define an array of acceptable property types $propTypes = array('Houses', 'Flats/Apartments', 'Bungalows','Commercial'); // if submitted value is in the array of acceptable types, use it // otherwise, use a wildcard character if (isset($_REQUEST['PropType']) && in_array($_REQUEST['PropType'], $propTypes)) { $PropType = "= '".$_REQUEST['PropType']."'"; } else { $PropType = "LIKE '%'"; } // check that the number of bedrooms is a number // if it's zero, search for all numbers if (isset($_REQUEST['NoBeds']) && is_numeric($_REQUEST['NoBeds']) && $_REQUEST['NoBeds'] == 0) { $NoBeds = '> 0'; } elseif (isset($_REQUEST['NoBeds']) && is_numeric($_REQUEST['NoBeds']) && $_REQUEST['NoBeds'] > 0) { $NoBeds = '= '.$_REQUEST['NoBeds']; } else { $NoBeds = '> 0'; } // if minPrice is not a number, set it to zero // otherwise, use the submitted value if (isset($_REQUEST['minPrice']) && !is_numeric($_REQUEST['minPrice']) || !isset($_REQUEST['minPrice'])) { $minPrice = 0; } elseif (isset($_REQUEST['minPrice']) && is_numeric($_REQUEST['minPrice'])) { $minPrice = $_REQUEST['minPrice']; } // if maxPrice is not a number, set it to 100 million // otherwise, use the submitted value if (isset($_REQUEST['maxPrice']) && !is_numeric($_REQUEST['maxPrice']) || !isset($_REQUEST['maxPrice'])) { $minPrice = 100000000; } elseif (isset($_REQUEST['maxPrice']) && is_numeric($_REQUEST['maxPrice'])) { $minPrice = $_REQUEST['maxPrice']; } mysql_select_db($database_db, $db); $query_Recordset1 = "SELECT * FROM property WHERE B_R = '$_POST[B_R]' AND Accepted = 'Yes' AND (City = '$_POST[q]') Or Postcode LIKE '%$q' Or Area = '$_POST[q]' AND PropType $PropType AND NoBeds $NoBeds AND Country = 'UK' AND Cost BETWEEN $minPrice AND $maxPrice ORDER BY Cost $sort"; $Recordset1 = mysql_query($query_Recordset1, $db) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise