Gossamer Forum
Home : Products : DBMan : Customization :

only return one link from textarea

Quote Reply
only return one link from textarea
among other fields in my database i have a textarea with links to pictures in it. sometimes there are 20+ pictures in it, sometimes only 5. i have customized my html_record that only the pictures field is returned. the problem is that the whole field is returned, not only one link from the field. my links are formatted like this:
Code:
<A HREF="link.to/picture.jpg">Here the description</A><BR>
is there a way to do some sort of "line-by-line" search and only return the link(s) that match the searchword?

Quote Reply
Re: only return one link from textarea In reply to
Code:

@lines = split /\n/,$rec{'FieldName'};
foreach $line (@lines) {
if ($line =~ /$in{'FieldName'}/) {
print "$line<BR>";
}
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
thanks for the reply, but where am i supposed to put this?
i tried in html_view_success and added:
Code:
my (@hits) = @_;
my (@lines) = split /\n/,$rec{'FieldName'};
foreach $line (@lines) {
if ($line =~ /$in{'FieldName'}/) {
print "$line<BR>";
}
}

my ($numhits) = ($#hits+1) / ($#db_cols+1);
then i added the @lines where it says:
Code:
for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits, @lines));
}
this still returned all the lines from the textarea... and i guess i did it totally wrong anyways :( could you please help me out here?

Quote Reply
Re: only return one link from textarea In reply to
Put it in sub html_record, where the record prints out. Wherever you want it to print out on your record display.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
thanks for the really fast answer. i got it to work, but still have some difficulties:

the number of hits aren't shown right. e.g. it says 12 matches, but only shows 7, on other searches it shows the correct number. i have done other searches and haven't seen any connection between the number shown and the matches (links) displayed.

it's even worse when it returns hits on different pages. for example i get 97 matches on 10 pages. the first page is empty, so is the next one. 2 of the 10 pages have links displayed, both pages with far more than 10 matches.

well, i could of course display all matches by default and delete the counter, but maybe there is a solution to this problem?

Quote Reply
Re: only return one link from textarea In reply to
My first guess is that you have a problem with your $db_key field. Or maybe you changed the number of fields in your .cfg file after you already had records in the database.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
i'm sorry to say that, but my fields print ok when i use the standard html.pl.

it must be the @lines thing that checks the lines one by one: when i search for the same word and just use print qq| $rec{'FieldName'} |; as html_record the records are shown on all pages the way it should be, but i also get the wrong lines as output that way. @lines deletes all the lines that don't have the word i searched for in it, but gives the normal number of lines as output - my guess :T

@lines screws up the $numhits and $maxhits. do you know a solution to do the hit-count after @lines deleted the lines without the searchword?

Quote Reply
Re: only return one link from textarea In reply to
Where did you put the code that I gave you?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
i changed nothing but the html_record:

Code:
sub html_record {
my (%rec) = @_;
($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

@lines = split /\n/,$rec{'Screenshot'};foreach $line (@lines) { if ($line =~ /$in{'Screenshot'}/) { print "$line<BR>"; }}

}
this will output like 8 empty pages, for example, 2 have hits displayed. when i change the html_record to

Code:
sub html_record {
my (%rec) = @_;
($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

print qq|
$rec{'Screenshot'}
|;


}
it will output 10 pages with all the hits displayed, also the wrong ones.

i have already tried to change the $in{'mh'} to $in{'Screenshot'} in html_view_success and changed other values as well, but no luck :(

Quote Reply
Re: only return one link from textarea In reply to
If you're getting errors with both of the codes you posted, the errors are not related to the modification I gave you here. It is something else.

What other modifications have you installed?

You might try setting $db_auto_generate = 1; in your .cfg file so that you can see what happens when you don't use html_record and html_record_form.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
no, i don't get errors with the $rec{'Screenshot'} code:

it outputs 10 pages for example, where all the links are displayed. it looks as it should. and i have the links i want on page 6 and 7. pages 1-5 and 8-10 are the wrong links that are displayed because it shows the whole 'Screenshot' field.

when i use your code, pages 1-5 and 8-10 are empty, because it deletes the links that don't contain the search-word. the only links displayed are on pages 6 and 7, just like when i use the simple $rec{'Screenshot'} code.

so my guess is: the whole results are counted, and the display is generated, with 10 pages. after that counting and generating the @lines deletes all the wrong links, but doesn't regenerate the display, so i still get 10 pages, from which 8 are empty.

do you know a way that the @lines is part of the generating and counting process? it should work like this:

1. get all the hits,
2. delete the wrong ones with @lines,
3. generate the display and count the lines/records
4. output the links

i would be more than happy if you knew a solution... Crazy

Quote Reply
Re: only return one link from textarea In reply to
At this point, I don't even understand the problem. Smile

Maybe I should go back to the beginning. This is what I understood your situation to be:

You would do a search on the Screenshot field.
Records that included the search text within the field would be returned.
You only wanted the lines that included the search text to be displayed.

Where did I go wrong?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
hehe, okeli, let me try to explain in other words... the problem really isn't that difficult, but maybe hard to explain; you would know in a second if you could do a search in my database.

to be more detailed: it's for a big german simpsons-site. i use the database to store the data for each simpsons-episode, like the episode title, written by etc. i also have this screenshot field. it's a textarea with links to screenshots:
Code:
<A HREF="../screenshots/1/1f02_homer_runs.jpg">Homer runs away</A><BR>
<A HREF="../screenshots/1/1f02_smithersandburns.jpg">Smithers talks to Mr Burns</A><BR>
for each episode i have a different number of screenshots.

with the normal html.pl everything works just fine. i search for something and everything is on the right place when i view the database.

now i have a section where only the screenshots should be searchable. so i copied the html.pl plus .cfg and renamed them to screenshots.pl and screenshots.cfg. i can login with db.cgi?db=screenshots, no error.

when i click "View" and search in the screenshot field, i used the standard $rec{'Screenshot'} for output.
with the example-code given above, a search for "Homer" would display:

Homer runs away
Smithers talks to Mr Burns


this is because it searches field by field, not line by line - and prints far too many records. this is how i get 10 pages full of links, most of them wrong.

so i asked for a function that searches line-by-line, and the @lines does exactly what it should: i only get

Homer runs away

the problem with this code occurs when the hits are displayed on more than one page. for example i get 10 pages as a search result, and only 2 of them contain data.

i think that this database works like this:
1. search the database
2. count the hits
3. generate the page based on the number of hits/page
4. send the page to the user

the @lines screws the display up, because it deletes the lines after the hits are counted and the display is generated, so it's 3b. or something. this bug only occurs when the number of hits without the @lines operation would be on more than one page.

what would maybe fix the bug is to implement the @lines command before the pages are generated. the @lines should be number 1b..

mhm, are things clearer now? i hope so - and sorry it turned out so long Frown

Quote Reply
Re: only return one link from textarea In reply to
There is no way that I know of to change the way the searching is done.

That being said, if you search for Homer on the Screenshot field, you should only be getting records that have Homer in the Screenshot field. Are you getting records that don't have Homer in the Screenshot field?


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
with your code searching is fine; and i also get the right results. but: all the hits are used to generate the result-pages, not only the hits for Homer

i'm looking for code that generates the result-pages out of the Homer results, not all results. all results in combination with the @lines code will result in these 8 blank pages. the search generates the pages for 100 hits, when the @lines cuts it down to 20 maybe.

Quote Reply
Re: only return one link from textarea In reply to
We are still having a major failure to communicate. I'm not sure which one of us is failing -- or maybe it's both.

You have a .db with records. All of those records have a field called "Screenshot." Some of those records have, within that field, the word Homer.

When you search in the "Screenshot" field for Homer, do you get all records returned, or only those records which have Homer in the "Screenshot" field?

I am thinking you would be better off with two databases -- one for the episodes and one for the screenshots. Then things would be a whole lot easier.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
Crazy i'll try to explain once more with different words:

the things that work:
1. i can search and get results
2. i only get results with Homer when i use your @lines function in html_record

this is 100% fine, as long as the results are displayed on one page only (!). if your results will display on more than one page, things get screwed up:

a.) when i use the normal $rec{'Screenshot'} command for html_record i can search for Homer and get results on 10 pages full of hits, most of them wrong because the whole Screenshot field prints. that's why i asked for this @lines code.

b.) when i use the @lines in html_record i can search for Homer and get results on 10 pages, but: the pages aren't full of hits.

the wrong links aren't shown, because @lines cuts them away. the empty pages are still generated because the @lines function starts working after the hits are counted and the pages are generated in html_view_success

are things clearer now? if not, you could contact me via icq (15421310), so i could give you my temporary ip and you could do a search on my database - it's not online yet...

Quote Reply
Re: only return one link from textarea In reply to
This is what I don't understand:

In Reply To:
a.) when i use the normal $rec{'Screenshot'} command for html_record i can search for Homer and get results on 10 pages full of hits, most of them wrong because the whole Screenshot field prints. that's why i asked for this @lines code.
It seems to me that you're telling me that you are getting records returned that don't have Homer in the Screenshot field. Is that what you're telling me?

I don't have ICQ. Sorry.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
when you do a search in dbman, too many hits are split into pages:
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

1.) with the normal $rec{'Screenshot'} command my page looks like this:

Page 7 example:
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

blah blah links
even more links
more...
some more...
maybe 20 lines more
...


[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

Page 8 example
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

links to screenshots
even more links

Here one Homer line
and another Homer link

...

[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

2.) when i use the @lines function in html_record pages 7 and 8 look like this:

Page 7 example:
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

Page 8 example
[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

Here one Homer line
and another Homer link


[<<] 1 2 3 4 5 6 7 8 9 10 [>>]

you see, page 7 is still generated as if all hits would display. but it's empty; and so are other pages, too. on page 8 the Homer hits stay.

Quote Reply
Re: only return one link from textarea In reply to
Right. But on page 7 there are no Homer lines. That's what I've been trying to get to. All of your problems would be solved if the search only returned records that had Homer lines, right? I'm trying to figure out why you're getting records that don't have Homer in the Screenshot field.

I know we've been going at this from opposite directions. From what you've said, though, it seems there is a problem with the search. It would be better to figure out what the problem is than to jury-rig some way around it. From experience, I know that if we do that, another problem will come up later on.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
In Reply To:
All of your problems would be solved if the search only returned records that had Homer lines, right?
all of my problems would be solved if the search would generate the pages out of the Homer lines. but it generates the pages with all the hits; and before the user sees the page deletes the lines without Homer. this results in these empty pages...

In Reply To:
I'm trying to figure out why you're getting records that don't have Homer in the Screenshot field.
this only happens when i don't use the @lines but the $rec{'Screenshot'} field. in my posting above i compared the results i get when using the different codes in html_record.

In Reply To:
From what you've said, though, it seems there is a problem with the search.
yes. from my understanding the @lines code is on the wrong place. it needs to be part of the html_view_success, where the hits are counted. i think html_record is just for the layout of the records. the @lines doesn't only change the appearance of the records, but also changes the number of the hits! that's why things screw up.

In Reply To:
It would be better to figure out what the problem is than to jury-rig some way around it.
the @lines code needs to be part of the html_view_success. this code:
Code:
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
should look something like this:
Code:
my (@hits) = @lines;
my (@lines) = split /\n/,$rec{'Screenshot'}; foreach $line (@lines) { if ($line =~ /$in{'Screenshot'}/) { print "$line<BR>"; }}

my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'Screenshot'} ? ($maxhits = $in{'Screenshot'}) : ($maxhits = $line);
...but i don't know the right code Crazy

In Reply To:
From experience, I know that if we do that, another problem will come up later on.
oh no, please not even more problems *sigh*

Quote Reply
Re: only return one link from textarea In reply to
In Reply To:
it needs to be part of the html_view_success, where the hits are counted.
But the hits are counted in sub query before they ever get to sub html_view_success.

Maybe I just cannot understand what you're saying or maybe you cannot understand what I'm saying or both. We've spent 20 (21 with this one) posts trying to convey information with no success whatsoever.

I am willing to help, but this is becoming extremely frustrating for me. (And, I'm sure, for you too.) Maybe someone else can figure out what's going on and help you. I just can't.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: only return one link from textarea In reply to
i put the database online and sent you a private message with the links. maybe this will help...

thanks