Need search within site code
Moderator: General Moderators
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
Need search within site code
i'm working on an e-commerce website for a school project and it requires a search within a site.
example: you go to somesite.com and they have a search text box and it searches for items within the site. thats what i'm looking for.
does anyone know how to do that, or does anyone know where to go to get code for that or anyone have any sample code that they could give me for a search query for a site? or could someone help me create a search query?
any help would be appreciated.
thanks
example: you go to somesite.com and they have a search text box and it searches for items within the site. thats what i'm looking for.
does anyone know how to do that, or does anyone know where to go to get code for that or anyone have any sample code that they could give me for a search query for a site? or could someone help me create a search query?
any help would be appreciated.
thanks
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
the items that i have within my site are stored in a mysql database.
here's the site i'm working on
http://www.wootenmedia.com/wootenmusic7/guitars.php
here's the site i'm working on
http://www.wootenmedia.com/wootenmusic7/guitars.php
I think you would have to do a query to search for specific words in the database! I see you have:
search.html?search=paint&submit=SUBMIT
All you would need to do is $_GET[''] the specific keyword, which is paint in the example above. Then do a mysql query to search for records which are LIKE the keywords.
search.html?search=paint&submit=SUBMIT
All you would need to do is $_GET[''] the specific keyword, which is paint in the example above. Then do a mysql query to search for records which are LIKE the keywords.
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
?
i used the code that you gave me above:
Code: Select all
<form action="<? $_SERVER['PHP_SELF']; ?>">
<font size="5" color="white"><strong>Search</strong></font>
<input type="text" name="search" size="13" maxlength="99">
<input type="submit" name="submit" value="SUBMIT" width="10" height="1">
</form>
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$tblname = "items";
$dbname = "db";
$item = $_GET['search'];
$link = mysql_connect("$host","$user","$pass") or die("Connection Error");
mysql_select_db($dbname) or die("Mysql Error!");
$query = "SELECT * FROM $tblname WHERE itemName LIKE '%'$itemName'%'";
$result = mysql_query($query) or die("Query Error!");
echo "$result";
?>
and it returns a result as Resource id #3.
why is it giving me this result?
also what else would i have to use in my code for the search, to search the mysql database and return results?
thanks-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
Try:
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$tblname = "items";
$dbname = "db";
$item = $_GET['search'];
$link = mysql_connect("$host","$user","$pass") or die("Connection Error");
mysql_select_db($dbname) or die("Mysql Error!");
$query = "SELECT * FROM $tblname WHERE itemName LIKE '%'$item'%'";
$result = mysql_query($query) or die("Query Error!");
echo "$result";
?>
Joe
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$tblname = "items";
$dbname = "db";
$item = $_GET['search'];
$link = mysql_connect("$host","$user","$pass") or die("Connection Error");
mysql_select_db($dbname) or die("Mysql Error!");
$query = "SELECT * FROM $tblname WHERE itemName LIKE '%'$item'%'";
$result = mysql_query($query) or die("Query Error!");
echo "$result";
?>
Joe
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
TRY:
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$tblname = "items";
$dbname = "db";
$item = $_GET['search'];
$link = mysql_connect("$host","$user","$pass") or die("Connection Error");
mysql_select_db($dbname) or die("Mysql Error!");
$query = "SELECT * FROM $tblname WHERE itemname = '$item'";
$result = mysql_query($query) or die("Query Error!");
echo "$result";
?>
That is getting rid of the like query altogether. It should work but im not sure... The above query will only look for exact keywords!
<?php
$host = "localhost";
$user = "username";
$pass = "password";
$tblname = "items";
$dbname = "db";
$item = $_GET['search'];
$link = mysql_connect("$host","$user","$pass") or die("Connection Error");
mysql_select_db($dbname) or die("Mysql Error!");
$query = "SELECT * FROM $tblname WHERE itemname = '$item'";
$result = mysql_query($query) or die("Query Error!");
echo "$result";
?>
That is getting rid of the like query altogether. It should work but im not sure... The above query will only look for exact keywords!
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact: