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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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