Solved

Search Engine

Posted on 2000-03-18
5
266 Views
Last Modified: 2010-03-05
Hi I am trying to make a search engine. I am new to Cgi. I know C++.I have a database will contain restaurants. It will have their names, location, and menu. People are going to be allowed to search using one of this options at a time.So people should be a provided a way to select the kind of search they want. multiple people searching at the same time is allowed. What people should get when they search is the name of the restaurant, its location and info on its menu. This is so if the place is found. If not found they should go to a page that says so.



Continuation of explanation:
lets say i have this tables:

TABLE: tblRestaurant (restaurant information)

Restaurant_ID (autonumber) Primary Key
Restaurant_Name (text)
Address (text)
Zip (text)
City (text)
State (text)
Country (text)
Rating (number)
Owner (text)
Employee_Number (number)
OpeningTimes (text)
Information (memo)

TABLE: tblMenu (restaurant menu information)
Menu_ID (autonumber)
Restaurant_ID (number) Foreign key -> tblRestaurant.Restaurant_ID
Meal_Type (number) (1 = starters, 2 = soups, 3 = salads, etc..)
Meal_Name (text)
Description (memo)
Price (text)

Things i would like help:

1. How do I make a form that allows me to search selecting diferrent methods? Like name of restaurant,menu,locatio,etc?

2. Since i know C++ i would like to implement the search done by the place name using a balanced search tree.
   a. How do you use C++ code in webpages?
   b. can a balanced search tree be done using perl?

3. For the other search selections i would like to use diferent kinds of search types...Is this Posible? Does perl allows for different types of search methods like C and C++ does?

Please Explain in detail each question, providing examples so i can guide myself.Points of question may rise.I would appreciate you put answer as comment like in the Access section so i can choose which answer I like cuz sometimes if question is locked other experts might not participate.
Thanx






0
Comment
Question by:q_low
  • 3
  • 2
5 Comments
 

Author Comment

by:q_low
Comment Utility
Adjusted points from 50 to 70
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
1. How do I make a form that allows me to search selecting diferrent methods? Like name of restaurant,menu,locatio,etc?
      use a html form that has list boxes listing your different search clauses

2. Since i know C++ i would like to implement the search done by the place name using a balanced search tree.
      Why ??
      this sound like a difficult way to solve a simple problem
      if your goin to use a database as a data store then sql will
      provide you with a interface to create complex/customisable
      searches

   a. How do you use C++ code in webpages?
      you dont use c++ in webpages. you use it to create web pages
      there are some library's probably similar to cgi.pm that will
      provide you methods to get in your environment vars etc. i have wrote my own      

   b. can a balanced search tree be done using perl?
      have no idea i use databases so sql is my search language

3. For the other search selections i would like to use diferent kinds of search types...Is this Posible? Does perl allows for different types of search methods like C and C++ does?
      probably.

below is an example that uses a simple single table access database.
it has one table called res with 3 colums region,name,id. a dsn has been created
in control panel to point at this db.
you will need to get/install dbi and the approriate dbd driver for your datebase
DBD:ODBC for access

use CGI;
use DBI;

$query = new CGI;

if($query->param())
{
   #$dsn = "my_dsn_i_set_in_control panel";
   $dsn = "paulsdb1";

   # open a connection
   $dbh = DBI->connect("dbi:ODBC:".$dsn, undef, undef) or die("problem");
   # prepare a statment
   $stmt = $dbh->prepare("SELECT * FROM res WHERE region = '".$query->param("category")."'") or die("problem");
   # execute it
   $stmt->execute() or die("problem");
   
   print $query->header();
   print("Results : <BR>");
   
   # loop through our results fetching each row as
   # a hash
   while($res = $stmt->fetchrow_hashref())
   {
      print("name : ".$res->{"name"}."<BR>")
   }
   # clean up our resources
   $stmt->finish();
   $dbh->disconnect();
}
else
{
   print $query->header();
   print("<HTML><BODY>
      <FORM ACTION=ee_perl.pl METHOD=POST>
         Select a category
         <SELECT NAME=category>
            <OPTION>greek
            <OPTION>italian
            <OPTION>thi
         </SELECT>
         <INPUT TYPE=SUBMIT VALUE=submit>
      </FORM>
   </BODY></HTML>");
}
0
 
LVL 10

Accepted Solution

by:
makerp earned 70 total points
Comment Utility
if your go to go down this route you will need to learn simple sql to do join accross tables etc ..
0
 

Author Comment

by:q_low
Comment Utility
this sound like a difficult way to solve a simple problem
if your goin to use a database as a data store then sql will
provide you with a interface to create complex/customisable
searches

What do you mean?
Where can i find more help on SQl?
I need to this this as fast as I can. In a way that I can be able to exoplain to others what I used and why.
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
have a look around the web for some sql tutorials. sql aint difficult. and for what your doing you will not need to go to deep into it.

here is a complete dbi example for perl. it makes use of an access database which has a single table called table1 with two columns name and address. set up a dsn in obdc in control panel to point to the db and call it test_db and then run the script at the cmd line.

# make use of the dbi module. for activeperl go to www.activestate.com/packages/zips and
# download the DBI package first and then download what ever DBD drivers you what to use
# this script makes use of the odbc driver module
use DBI;

# the dbd driver we actually want to use
$DBI_DRIVER = "ODBC";

# the dsn info
$DATA_SOURCE = "test_db";
$DATA_SOURCE_USERNAME = "";
$DATA_SOURCE_PASSWORD = "";

# global database handle for this script
my $dbh;

# connect to database, the first parameter will take the form of 'dbi:ODBC:test_db'
$dbh = DBI->connect('dbi:'.$DBI_DRIVER.':'.$DATA_SOURCE,$DATA_SOURCE_USERNAME,$DATA_SOURCE_PASSWORD)
      || die("Connection error : ".$DBI::errstr);

# set the LongReadLen really high incase we have meno fields
$dbh->{LongReadLen} = 30000;

# prepare a stmt, this returns a statment handle
$sth = $dbh->prepare("SELECT * FROM table1") || die("Stmt error : ".$dbh->errstr);


print("Expected fields to be returned from first query.......\n");
@fi = $sth->{'NAME'};
for($i=0;$i<$sth->{'NUM_OF_FIELDS'};$i++)
{
      print("field : @{$fi[0]}[$i]\n");
}

# execute our stmt
$sth->execute() || die("Stmt error : ".$dbh->errstr);

# if we are debugging then we may wish to dump our result in one hit
# the dump_results function uses default values for row delimiter's etc
# these can be overridden
# dump_results(st_handle,maxlen,row_delimiter,field_delimiter,fileh_for_dump)
print("Dump of the results returned by stmt, for debugging purposes\n");
DBI::dump_results($sth);

print("\nNormal results retrival using a loop to go through each row returned\n");
# execute our stmt
$sth->execute() || die("Stmt error : ".$dbh->errstr);

# fetch and print the rows, returns undef on failure, hash reference on success
while($dat = $sth->fetchrow_hashref())
{
      # get the name field from our hashref
      print("Name : ".$dat->{"name"}."\t Address : ".$dat->{"address"}."\n");
}

# finish the statement handle, if we dont do this the disconnect function will spew some errors
$sth->finish();

print("\nDoing some inserts into the database\n");
# set auto commit to false so we have to explicetly call commit on the database handle
$dbh->{"AutoCommit"} = 0;
# we can prepare a stmt and execute it several times with different values in the place holders like this
$sth = $dbh->prepare("INSERT INTO table1 (name,address) VALUES (?,?)") || die("Stmt error : ".$dbh->errstr);
# execute it but this time pass the values we want to replace the place holders
$sth->execute("bart","saturn") || die("Stmt error : ".$dbh->errstr);
# commit it
$dbh->commit() || die("Stmt error : ".$dbh->errstr);
# turn auto commit back on
$dbh->{"AutoCommit"} = 1;
# finish with the stmt handle
$sth->finish();

print("\nDoing an update on all records (changing address to mars)\n");
# we can use the do function to execute a stmt and get the number of rows it affected
$rows = $dbh->do("UPDATE table1 SET address = 'mars'") || die("Stmt error : ".$dbh->errstr);
print("That affected ".$rows." rows\n");

# now print the updated table out
print("\nUpdated table contents are : \n");
$sth = $dbh->prepare("SELECT * FROM table1") || die("Stmt error : ".$dbh->errstr);
$sth->execute() || die("Stmt error : ".$dbh->errstr);

while($dat = $sth->fetchrow_hashref())
{
      # get the name field from our hashref
      print("Name : ".$dat->{"name"}."\t Address : ".$dat->{"address"}."\n");
}
$sth->finish();

print("\n\tBye bye.... Shutting up shop !!!!");
# closes the database
$dbh->disconnect();

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now