Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching again

Status
Not open for further replies.

altaratz

ISP
Apr 15, 2001
73
US
I'm sorry to keep posting this problem, but I'm using a cgi to search through a text database for records that have one particular field filled in (specifically, for vendors that are offering discounts/special deals. When I run the cgi, I have it set to search the particular field the discounts - all vendors with dicounts have something in the field, those who dont have discounts, have a blank field. However, when I output the results, it gives me every freaking entry in the database - please help - code for the search_record subroutine is below - thanks so much!

Ethan Altaratz


#build the search line with all fields we want to search in
$searchline = $discount;


#search by keywords
# only perform the keyword search if the length of the search string is greater than 2
# don't think we want people to search for and or or etc.
$sfound = 0;
$found = 0;
$notfound = 1;

$stlen = length($searchstring);
if ($stlen > 1) {
@words = split(/ +/,$searchstring);
foreach $aword (@words) {
if ($searchline =~ /\b$aword/i) {
$sfound = 1;
}
else {
$notfound = 0;
}
}
}
if ($sfound == 1 && $notfound == 1) {
$found = 1;
}

# if search string is too small .. set found to 1
if ($stlen <= 1) {
$found = 1;
}
#if page doesn't have a title then return not found
$tlen = length($linktitle);
if ($tlen < 1) {
$found = 0;
}
}


#####And here is the output html/javascript I'm using the results for:


print &quot;message[$msg]=\&quot;$discount|Girl band All Saints were knocked off the top spot in the British charts on Sunday.|print &quot;\n&quot;;

$msg ++;


--so the only entries into this array should be the vendors with discounts listed, but it keeps giving me every entry
:-(
 
i'm not sure i'm following it correctly - i don't even see where the whole database is? is this bit of code being called over and over for every entry in the database? well, if so, that's fine. at the end, you finally set the variable '$found' to true or false, depending on whether or not the field matched the search. however, after that, i don't see the variable tested. shouldn't there be something like:[tt]
if ($found)
{print stuff}
else
{don't print stuff}[/tt]


X-) &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top