Gossamer Forum
Home : Products : DBMan SQL : Development, Plugins and Globals :

Help with extracting only the start of a field value

Quote Reply
Help with extracting only the start of a field value
Hi!
Back after a holiday break with the urge to get DBMan SQL doing even greater things. Can anyone help me with the following task? I have a global called <%get_data%> which retrieves what is in a field in a particular record of a table:

sub {
my ($table, $field, $value) = @_;
my $sth = $DB->table($table)->select({ $field => $value });
my @output;
while (my $rs = $sth->fetchrow_hashref ) {
push @output, $rs;
}
return { loop_hash => \@output };
}

The global is called this way:
<%get_data('Articles','RecordID',21)%>
<%loop loop_hash%>
<%Content%>
<%endloop%>

This works fine, returning the ENTIRE content of the field <%Content%> in the record numbered 21 of table Articles.
What I would like to do is display >> only the first few paragraphs (say first 2) << of the field <%Content%>.

Now I already have a separate global that does this:
<%display_paras x,y%> # x=initial para, y=last para to show

sub {
my ($low, $high) = @_;
my ($tags) = GT::Template->tags;
my (@paras) = split /\r?\n/, $tags->{Content};
my $numberparas = @paras;
scalar @paras > $high or return join ("", @paras[$low..$numberparas]);
return join ("", @paras[$low..$high]);
}

The challenge is adapt the <%get_data%> global to display first few paragraphs of <%Content%>.
Thanks in advance for any assistance!
Charly
Subject Author Views Date
Thread Help with extracting only the start of a field value charly 4430 Aug 27, 2003, 2:30 AM
Thread Re: [charly] Help with extracting only the start of a field value
pugdog 4243 Sep 15, 2003, 8:14 AM
Post Re: [pugdog] Help with extracting only the start of a field value
charly 4247 Sep 15, 2003, 8:23 AM