Jump to content

Please help!lSearch Function


HerIT

Recommended Posts

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 ;D

this is what i done so far

<?php
session start();
//---THIS IS FOR "KEYWORDS" FIELD---
$keywords=($_POST['keywords']);

//check if field is blank
if (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

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.

Archived

This topic is now archived and is closed to further replies.

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