/    Sign up×
Community /Pin to ProfileBookmark

searching help !!

hi,
i am trying to search a database with car parts info in it. The user types a part name with year he/she gets the expected results. sounds simple, but i am having problems. here is how everything is put together [abstract].

mysql


_____________________________________________

year_from | year_to | make | model | part_name
98 | 04 | honda | civic | COVER PRIMED FRONT
92 | 95 | honda | civic | fender
93 | 96 | honda | civic | engine

the form


_____________________________________________

<form name=”form” action=”search.php” method=”get”>
<input maxlength=”17″ type=”Text” name=”q”></td>
<input type=”submit” name=”Submit” value=”Search”/>
</form>

php codes [search.php]


_____________________________________________

<?
mysql_connect (host, username, password);

mysql_select_db(“db”) or die(“Unable to select database”);

$query = “SELECT * FROM parts WHERE make LIKE ‘$q’ ||
model LIKE ‘$q’ || part_name LIKE ‘$q’ || year_from LIKE ‘$q’ || year_to LIKE ‘$q'”;

while ($row= mysql_fetch_array($result)) {
$make = $row[“make”];
$model = $row[“model”];
$part_name=$row[“part_name”];
$year_from = $row[“year_from”];
$year_to = $row[“year_to”];
$quantity=$row[“quantity”];

echo “$row[“model”]<br>”;


?>


_____________________________________________

so far, i have been able to ONLY get just by year, or make, or model, or part name, but not a combination. to make matters a bit more complex i am trying to find parts by typing:

“94 civic” ——–> 94 is not inventory but is between year_from and year_to

i should get two results, and print them out. i haven tried more than couple ways but so far have not achieved my goal.

also, i can’t figure out how to get results that fall between the years_from and year_to.

ie.

93 95
92 97
92 96

find 94..

thanks in advance for you help.

sincerely,
fusi0n

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJul 27.2004 — use % around search terms and you'll get more results, example:[code=php]$query = "SELECT * FROM parts WHERE make LIKE '%{$_GET['q']}%' OR
model LIKE '%{$_GET['q']}%' OR part_name LIKE '%{$_GET['q']}%' OR year_from LIKE '%{$_GET['q']}%' OR year_to LIKE '%{$_GET['q']}%'";[/code]
×

Success!

Help @fusi0n spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...