kaozdragon Posted July 15, 2007 Share Posted July 15, 2007 i've looked online and so far i've only gotten scripts of the search engines where they do full-text searches or the ones that retrieve one variable in the database and retrieve it. i've been able to squeeze in 2 variables but when i do more, it starts to mess up. just wondering if there was a better way of doing this, rather than setting all empty variables to an abiguous number that will match all comps. so to recap, i have 2 questions. 1. how do you filter out more than 1 variable in a mysql database search? 2. is there a better way to do this than what i'm doing? <?php include("connect.php"); include("head.php"); //get variables $brand = ("[^a-z0-9A-Z]", "",$_POST["brand"]); $hddcap = ("[^a-z0-9A-Z]", "",$_POST["hddcap"]); //if hddcap does not exist, makes it 0 if (!$hddcap) {$hddcap = 0;} echo "<center>Results</center><BR>"; //print results $result = mysql_query("SELECT * FROM computers WHERE brand LIKE '%$brand%' && hddcap>'%$hddcap%' ORDER BY series, model"); while ($row = mysql_fetch_array($result)) { echo "<a href='computer.php?id=" . $row['id'] . "'>" . $row['brand'] . "'s " . $row ['series'] . " " . $row['model'] . "</a><br>"; } include("foot.php"); ?> Quote Link to comment Share on other sites More sharing options...
Oldiesmann Posted July 15, 2007 Share Posted July 15, 2007 I don't have much experience with searching and such, so I'm not sure if there's a better way to do that, but there's a minor typo in the query... It should be hddcap LIKE '%$hddcap%' (or hddcap>'$hddcap' if the variable is 0 - otherwise you'll get anything where hddcap has a 0 in it). I'm assuming you meant to put preg_replace after the = in those two "get variables" lines... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.