Search Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HerIT
Forum Newbie
Posts: 2
Joined: Tue Nov 21, 2006 12:53 am

Search Function

Post by HerIT »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi  
Im working on a search function. Im totally new to programming  Its really basic, just searching based on keywords so i learnt about partial match....

This is what i have done so far.....

Code: Select all

<?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? Im not too sure..... :?

This my .html

Code: Select all

<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>
sorry im really new...
As you can see, i need to do for drop down list and checkboxes too


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

r u getting any error message?
change:

Code: Select all

$search=%+$keywords+%;
to

Code: Select all

$search="%".$keywords"%";
and try. report if there is any error message.
HerIT
Forum Newbie
Posts: 2
Joined: Tue Nov 21, 2006 12:53 am

Post by HerIT »

I still haven "check" it so i not sure.

$search="%".$keywords"%"; <-- for all versions of PHP?
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

Check that first, and u have to make another change:

Code: Select all

$numrows=mysql_numrows($result);
to

Code: Select all

$numrows=mysql_num_rows($result);
.

have fun with php.
Post Reply