I managed to get Links to work with MySQL database today thanks to Alex's valuable help. I have a problem however. The "SQL Power Search" version of Links has a extensively modified "search.cgi" file in order to have it query MySQL correctly. I'm really confused on how to make the SQL's search.cgi file to work with "Category Searcher" mod by Edward Bownass. You see, the one that Edward Bownass have on his site works on the original version of Links and NOT the SQL Power Search version. I need some help in this if anybody knows what to change in order to have this mod work.
This is what I've done so far:
In the SQL version of search.cgi file, I added the following lines based on my comparison of the Category Search Mod-- file search.cgi.
# See if we have something to search for.
if ($in{'query'}) {
if ($in{'where'}) { # If there is a variable where, it send the data to the new search routine
&sql_searchcat();
}
else {
&search(); # Otherwise it just does a normal search.
}
Next I added a NEW routine as mentioned above called "sql_searchcat". This is how it looks:
sub sql_searchcat {
# --------------------------------------------------------
# Searches a sql table instead of the flat file..
my ($drh, $dbh, $sth, $query, $bool, $numhits, @results);
# Connect to the database
$dbh = Mysql->Connect ($sql_host, $sql_database, $sql_username, $sql_password) or &cgierr ("SQL: Unable to connect to database. Reason: $Mysql::errstr.");
# Get the Link matches..
($in{'bool'} eq "or") ? ($bool = "OR") : ($bool = "AND");
$query = qq!
SELECT * FROM $sql_search
WHERE !;
foreach $term (@search_terms) {
$query .= qq!
(!;
foreach $field (@sql_search_fields) {
$query .= qq!
$field LIKE '%$term%' OR!;
}
chop ($query); chop ($query);
$query .= qq!
) $bool!;
}
chop ($query); chop ($query); chop ($query);
$query .= qq!
ORDER BY Title !;
# Perform the Query..
$sth = $dbh->Query ($query) or &cgierr ("SQL: Unable to query database. Reason: $Mysql:
b_errstr.\nQuery: $query\n");
while (@results = $sth->FetchRow) {;
push (@{$link_results{$results[$db_category]}}, @results);
}
# Temp
$link_query = $query;
# Get the Category Matches (only if we are not getting a next set of hits..)
$query = qq!
SELECT DISTINCT Category
FROM $sql_search
WHERE !;
foreach $term (@search_terms) {
$term =~ s/\s/_/g; # We replace spaces with _ as Category names don't have spaces..
$query .= qq!
Category LIKE '%$term%' $bool!;
}
chop ($query); chop ($query); chop ($query);
$query .= qq!
ORDER BY Category !;
# Perform the Query..
$sth = $dbh->Query ($query) or &cgierr ("SQL: Unable to query database. Reason: $Mysql:
b_errstr.\nQuery: $query\n");
while ($category = $sth->FetchRow) {;
push (@category_results, $category);
}
# Temp
$category_query = $query;
}
OK, very long and confusing and I'm SORRY. But that's the only way I can think of to explain my problem. Anyway, what do I have to change in the new sub routine to have it work like the Edward Bownass mod?
Any help would be appreciated.
John
[This message has been edited by jmurphy (edited November 16, 1998).]
This is what I've done so far:
In the SQL version of search.cgi file, I added the following lines based on my comparison of the Category Search Mod-- file search.cgi.
# See if we have something to search for.
if ($in{'query'}) {
if ($in{'where'}) { # If there is a variable where, it send the data to the new search routine
&sql_searchcat();
}
else {
&search(); # Otherwise it just does a normal search.
}
Next I added a NEW routine as mentioned above called "sql_searchcat". This is how it looks:
sub sql_searchcat {
# --------------------------------------------------------
# Searches a sql table instead of the flat file..
my ($drh, $dbh, $sth, $query, $bool, $numhits, @results);
# Connect to the database
$dbh = Mysql->Connect ($sql_host, $sql_database, $sql_username, $sql_password) or &cgierr ("SQL: Unable to connect to database. Reason: $Mysql::errstr.");
# Get the Link matches..
($in{'bool'} eq "or") ? ($bool = "OR") : ($bool = "AND");
$query = qq!
SELECT * FROM $sql_search
WHERE !;
foreach $term (@search_terms) {
$query .= qq!
(!;
foreach $field (@sql_search_fields) {
$query .= qq!
$field LIKE '%$term%' OR!;
}
chop ($query); chop ($query);
$query .= qq!
) $bool!;
}
chop ($query); chop ($query); chop ($query);
$query .= qq!
ORDER BY Title !;
# Perform the Query..
$sth = $dbh->Query ($query) or &cgierr ("SQL: Unable to query database. Reason: $Mysql:
b_errstr.\nQuery: $query\n"); while (@results = $sth->FetchRow) {;
push (@{$link_results{$results[$db_category]}}, @results);
}
# Temp
$link_query = $query;
# Get the Category Matches (only if we are not getting a next set of hits..)
$query = qq!
SELECT DISTINCT Category
FROM $sql_search
WHERE !;
foreach $term (@search_terms) {
$term =~ s/\s/_/g; # We replace spaces with _ as Category names don't have spaces..
$query .= qq!
Category LIKE '%$term%' $bool!;
}
chop ($query); chop ($query); chop ($query);
$query .= qq!
ORDER BY Category !;
# Perform the Query..
$sth = $dbh->Query ($query) or &cgierr ("SQL: Unable to query database. Reason: $Mysql:
b_errstr.\nQuery: $query\n"); while ($category = $sth->FetchRow) {;
push (@category_results, $category);
}
# Temp
$category_query = $query;
}
OK, very long and confusing and I'm SORRY. But that's the only way I can think of to explain my problem. Anyway, what do I have to change in the new sub routine to have it work like the Edward Bownass mod?
Any help would be appreciated.
John
[This message has been edited by jmurphy (edited November 16, 1998).]

