?
Solved

Site Search

Posted on 2003-03-09
11
Medium Priority
?
197 Views
Last Modified: 2008-07-12
Hello,

I would like to impliment a site search on my web server.
Could somone help me with this.

Thanks
0
Comment
Question by:fibdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 

Expert Comment

by:nikotto
ID: 8099212
look at this page, there are some ready to use scripts:
http://php.resourceindex.com/Complete_Scripts/Searching/Searching_Your_Web_Site/
0
 
LVL 15

Expert Comment

by:VGR
ID: 8101370
other solution : YOU know WHERE in your site (DB ?) you can find relevant data, and YOU build a simple HTML FORM for people to enter keywords, dates and such, and YOU run/display the query and it's results.
If you only want to provide "full-text" search on static pages on all of your site, then use the provided link above or any free search module.
0
 
LVL 3

Author Comment

by:fibdev
ID: 8106696
I've looked into the search modules and I think I'm leaning toward a database driven solution.  My site is of moderate size, so it won't take me long to index it.  I am new to php and will need help setting up.  I think for now, I just want to provide keyword searches from a simple textbox and button form.  See http://www.fibdev.com for example.  I've created the form already.  I just need help with the php and how I should set up the table.  Here is the information I would like to display.

Link
Page Title
A few limes of text

Next result...

Next result...

Let's call the table "sitesearch"  Thanks up front for your help.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:fibdev
ID: 8140663
I still need help with this... Is anyone out there.  I'm new to php and would like a script to queary this table and display these results.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8141729
so let me summarize :
1) you have a 100% static website
2) you intend to build a small DB to hold the "keywords" and page references where they appear
3) then you've the FORM that enables the user to enter any combiantion of keywords, or only one (simplier)
4) you need a small PHP source to take the data from the FORM, query the DB accordingly, and return the pages' references in
0
 
LVL 15

Expert Comment

by:VGR
ID: 8141735
so let me summarize :
1) you have a 100% static website
2) you intend to build a small DB to hold the "keywords" and page references where they appear
3) then you've the FORM that enables the user to enter any combiantion of keywords, or only one (simplier)
4) you need a small PHP source to take the data from the FORM, query the DB accordingly, and return the pages' references in a list

Am I right ?

Then I need to see your FORM (for fields' names and ACTION= and METHOD=)
Also tell me if you use register_globals=On or Off
And finally what philosophy of search you need so that I can build the DB layout for you

If ever you add a new page or modify somepages, you'll need a mechanism to update the "index/search" DB
0
 
LVL 3

Author Comment

by:fibdev
ID: 8147803
I am able to modify the database.  My host provides me with a very useble Database Manager.  The form is simple.

<form method="POST" action="/sitesearch/search.php" style="border-right: 1 solid #647C88; border-bottom: 1 solid #647C88">
            <p style="margin-left: 8">
            <font face="Century Gothic" size="1" color="#647C88">Search for</font>
            <br>
            <input type="text" name="SearchString" size="16">&nbsp;
<input type="submit" value="Go" name="Button1">

register_globals is On.
0
 
LVL 15

Accepted Solution

by:
VGR earned 600 total points
ID: 8149735
yes, simple indeed :D

good good good

Just make sure that your script generating the form has session_start(); at the beginning

Build this script now :
----------------search.php ----------------
<?
session_start();
//tracking problems beforehand ;-)
echo "<!--transmitted search value = '$SearchString'--><BR>";
// note also that SearchString could have been addslashes()-ed, depending on your magic quoting configuration, so may-be a call to stripslashes() will be required.

// ok, now query the DB
require_once("database_def.inc.php"); // $dbHost, $dbName, etc
$linkID=mysql_connect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());
mysql_select_db($dbName,$linkID) or die ("bad select db. ".mysql_error());

// if you want the exact string :
$query="SELECT * FROM yourtable WHERE yourkeywordfield LIKE '%SearchString%';"; // [ORDER BY]
// if you want a "any word within" search :
// explode on ' ', implode on '%\' OR \'%', you got the picture

// effectively query DB
$result=mysql_query($query,$linkID) or die ("bad query '$query' : ".mysql_error());

// now display results
if (mysql_num_rows($result)>0) {
  while ($res=mysql_fetch_array($result)) {
    // get data
    $locID=$res["id"];
    $locfield1=$res["field1"]; // your table layout commands here
    // display result
    echo "result: $locfield1<BR>"; // ditto, please precise.
  } // while results
  // here whatever after the results, like echo "X results found"... or a mysql_close() - not necessary
} else echo "No Results.<BR>";
?>
0
 
LVL 3

Author Comment

by:fibdev
ID: 8156174
I think I can work with this.  Thank you.

I will impliment this tommorow and award the points.  I shouldn't need anything else, but we will see.

:)
0
 
LVL 3

Author Comment

by:fibdev
ID: 8319009
I never did get this working.  Thank you for trying.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8319039
why ? it's crystal clear... what are the errors ?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question