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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching Problem

Status
Not open for further replies.

altaratz

ISP
Apr 15, 2001
73
0
0
US
Can someone look at this code - it's killing my univserse.

This .cgi searches for entries in a textfile only in one particular data field - it's intended to find just the one entry by its ID number, and to then use the information for that record to print an informational page on just that entry - however, even when I enter the exact number as a search string it pulls all of the entries in teh database, even though they have different ID numbers. Please -help!



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


#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;
}
}
 
<grin> Hi Altaratz

Your bit of code:


foreach $aword (@words) {
if ($searchline = /\b$aword/i) {
$sfound = 1;
}

should look a bit like this...

foreach $aword (@words) {
if ($searchline =~ /\b$aword/i) {
$sfound = 1;
}

From the rest of your code it looks as though you'll understand what I mean -- but just shout if you don't.
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Mike,

I'm guess I'm having what they technically call a &quot;brain fart&quot; - I'm still not getting how to fix the problem - I'd really appreciate the full solution. Thanks very much - here's the code again wih your tilde' - Take care!

Ethan


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


#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;
}
}
 
no, you missed it. that line doesn't need the tilde, it's 10-20 lines down that it's needed. look carefully at Mike's post, find the code that matches, and change it. &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