Forum Moderators: coopster & phranque

Message Too Old, No Replies

Keeping track of what has already been displayed

         

dreaming of nascar

7:55 am on Apr 22, 2003 (gmt 0)

10+ Year Member



I have a text file that contains the products on my site in it. I am building a site search script and am running into problems. One of the products on my site are books. I have the summary of the book in the file. I get the summary pulled out of the file fine and get each word separated into an array fine. My problem is that if there is more than one of the same word in the array it displays the same product however many times the word is found. Obviously, I do not want this to happen. Does anyone know of a way I could keep track of which products have already been displayed? I have a unique product ID number at the beginning of each record. I was thinking about using that in some fashion, but cannot come up with a way to achieve this. I am using foreach loops because the number of words obviously varies from book to book. Below is what a record in the file would look like. Thank you for any advice/tips you can give.

ProductIDŠPriceŠTitleŠAuthorŠDescription

D O N

DrDoc

7:40 pm on Apr 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First off, are we talking Perl or PHP?

dreaming of nascar

7:54 pm on Apr 22, 2003 (gmt 0)

10+ Year Member



Perl. Sorry, I forgot to mention this I guess

D O N

DrDoc

8:37 pm on Apr 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I just thought of something... is it possible to sort the data first? If so, they will be grouped by the product ID...

$prev = "";
foreach($temp) @myarray {
if(!($temp =~ /^$prev\¦/)) {
@mylist = split(/\¦/,$temp);
...
do stuff
...
$prev = $mylist[0];
}
}

$prev will be the previous product ID... if the next summary in the array starts with the same product ID it will be skipped...