View Full Version : Search function for an online store
vickree
05-28-2008, 09:35 PM
Hello all,
I'm a little new too PHP and MySQL. I've been asked to attempt to create a search function for part of an online store. Does anyone know of any tutorials that can help me with this?
I appreciate all suggestions. Thank you!
Fumigator
05-29-2008, 12:26 AM
Google "fulltext index" +"mysql".
brazenskies
05-29-2008, 08:36 AM
to start you off, create a form with a search box and a button.
Send that form to a search results page.
execute your sql string with the search value, being the value from the box on the previous form.
Create a recordset and display the results.
To be honest, there's not really much more to it than that!
vickree
05-29-2008, 11:06 PM
Thanks, I started by doing that - and for the most part it seems to work alright :)
It's referencing the database, but Can I do this using Keywords? Right now I have to type in the entire name without any errors, I cant use just parts from the word...
E: I have to search "Chef Uniform Pants" to pull up the "Chef Uniform Pants"
When I would like to be able to type in "Chef" "Uniform" or "Pants" and be able to pull up that and others....
Any ideas what I'm missing?
whizard
05-29-2008, 11:09 PM
The first post.
Google "fulltext index" +"mysql".
Fumigator wasn't sending you away because he didn't feel like answering your question, he was providing you with a source of information on the topic you asked about.
HTH
Dan
brazenskies
05-30-2008, 08:36 AM
Thanks, I started by doing that - and for the most part it seems to work alright :)
It's referencing the database, but Can I do this using Keywords? Right now I have to type in the entire name without any errors, I cant use just parts from the word...
E: I have to search "Chef Uniform Pants" to pull up the "Chef Uniform Pants"
When I would like to be able to type in "Chef" "Uniform" or "Pants" and be able to pull up that and others....
Any ideas what I'm missing?
tried using LIKE?
vickree
06-02-2008, 04:38 PM
<?
Sensitive information removed
?>
<form method="post" action="database.php">
<input type="text" size="30" maxlength="28" name="look"><br>
<input type="submit" value="SEARCH!">
</form>
<?
$result = mysql_query ("SELECT firstName
FROM `testTable`
WHERE MATCH (
details
)
AGAINST (
'guru'
) ");
echo $result;
?>
------------------------------------------
http://www.victoriacosens.com/TJdist/database.php
Resource id #2 comes up - when im looking for 'Ben' to come up...
When I type that code into my phpMyAdmin the correct response comes up...
Any input will be greatly appreciated! :)
abduraooft
06-02-2008, 04:48 PM
You need to fetch the values from the query result. see the manual http://in2.php.net/mysql_fetch_row
vickree
06-16-2008, 03:59 PM
Hi, Im back again with a little different error. I had this working on my own database and server - I exported the database to where the new one is. And just moved the code over - switching the connection to the database to the correct one.
Anyways, this was working perfect on my server... but now for some reason, i cannot reference the search variable properly... here is what I have.
<!-- Start of Search Function --><br>
<br>
Please type the name of the product you would like to find.
<form method="post" action="search_test.php">
<input type="text" size="30" maxlength="28" name="search">
<input name="submit" type="submit" value="SEARCH!">
</form>
<!-- end of search -->
<?
//Pulling the results for matching words
$result = mysql_query ("SELECT image, location, itemName, price
FROM `tj_search`
WHERE MATCH (
details
)
AGAINST (
'$search'
) ");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf(
"<br><img src=%s/> - <a href=%s> %s</a> - $ %s
<br>", $row[0], $row[1], $row[2], $row[3]);
}
mysql_free_result($result);
?>
If you substitute "AGAINST ('$search'" for one of the keywords I would try searching, it'll pull up all those in the page where I wanted it... Am i missing something obvious?
Thanks
abduraooft
06-16-2008, 04:25 PM
$result = mysql_query ("SELECT image, location, itemName, price
FROM `tj_search`
WHERE MATCH (
details
)
AGAINST (
'$search'
) ");
If you substitute "AGAINST ('$search'" for one of the keywords I would try searching, it'll pull up all those in the page where I wanted it... Am i missing something obvious?
One way to debug such type of errors is trying to echo the query and check whether it's OK, say
echo $sql= "SELECT image, location, itemName, price
FROM `tj_search`
WHERE MATCH (
details
)
AGAINST (
'$search'
) ";
$result = mysql_query ($sql);
// and so on
Check whether $search is getting substituted correctly.
I guess, you missed to assign the value from the $_POST array!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.