HerIT Posted November 21, 2006 Share Posted November 21, 2006 Hi. :DIm working on a search function for a website. Its reall the basic one. Just searching by keywords.Anyone can help me by telling me where can i find sample codes for a basic search function? Just searching by key words. Thanks ;Dthis is what i done so far<?phpsession start();//---THIS IS FOR "KEYWORDS" FIELD---$keywords=($_POST['keywords']);//check if field is blankif (empty($keywords)){ echo 'this field cannot be blank'; // use partial match $search=%+$keywords+%;//link to database $link=mysql_connect('localhost','root','') or die ("Error connecting to database."); mysql_select_db('savory') or die ("Error connecting to database."); $result=mysql_query("select * from webpage where keywords='$search'",$link); mysql_close($link);//displace search results$numrows=mysql_numrows($result); for(i=0;i<$numrows;i++)}IS that how you displace search results?search.html<html><head><title>Search</title></head><body><table><form method="POST" action="search.php"><tr><td>Keywords: <input type="text" name="keywords" size="20"></td><td><select name="category"><option value= "news"> News<option value= "shopping"> Shopping<option value= "education"> Education</td></tr><tr><td height="60"><b>Please tick only one</b></td></tr><tr><td>URL<INPUT type="checkbox" name="url"></td><td>Note<INPUT type="checkbox" name="note"></td><td>Title<INPUT type="checkbox" name="title"></td></tr><tr> <td height="60"><input type="submit" value="Search" name="search"></td></tr></form></table></body></html>Now i only working on searchin by keywords, later then by categories .... Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/ Share on other sites More sharing options...
heckenschutze Posted November 21, 2006 Share Posted November 21, 2006 So categorize the keywords using another column ?Or search directly from the category tables -- if they exist ? Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/#findComment-127831 Share on other sites More sharing options...
HerIT Posted November 21, 2006 Author Share Posted November 21, 2006 This search function is for a Book marking website. first ask users to type in keywords and then choose a option from a dropdownlist( a category of the links) etc. romance, news,education.Now that i can search by the keywords the user type in, how do i program it so that i can search by category too....If im not wrong, these does the search by keywords:$keywords=($_POST['keywords']);$link=mysql_connect('localhost','root','') or die ("Error connecting to database.");mysql_select_db('savory') or die ("Error connecting to database.");$result=mysql_query("select * from webpage where keywords='$search'",$link);Im rather new. For dropdownlist, how do we define?$category=($_POST['category']); ?coz im thinking its a dropdownlist, the coding to define may be different....Also, i duno how to use the SQL statement to search by category from what the user choose from the dropdownlist. Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/#findComment-127888 Share on other sites More sharing options...
HerIT Posted November 21, 2006 Author Share Posted November 21, 2006 Someone help? ??? Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/#findComment-127931 Share on other sites More sharing options...
HerIT Posted November 22, 2006 Author Share Posted November 22, 2006 please? :-[ Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/#findComment-128260 Share on other sites More sharing options...
hitman6003 Posted November 22, 2006 Share Posted November 22, 2006 http://www.phpfreaks.com/tutorials/129/0.php Link to comment https://forums.phpfreaks.com/topic/27947-please-helplsearch-function/#findComment-128261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.