Jump to content

Creating a database search engine


kaozdragon

Recommended Posts

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");
?>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.