Gossamer Forum
Home : Products : DBMan : Customization :

Display only part of field..

Quote Reply
Display only part of field..
I got a field that goes like this.. |County/Town/PropertyType|

I use the long/short mod to display the results.. How is it that when the list of results is output.. I can get it to display only the PropertyType or the last part of this field only..

Thanks in advance.. Justin.
Quote Reply
Re: [JustinS] Display only part of field.. In reply to
Is the format always: itemslashitemslashitem ?

How do you ensure that end users won't do County-Town-PropertyType ?
Quote Reply
Re: [Watts] Display only part of field.. In reply to
The format will always be entered in as "itemslashitemslashitem" ie County/Town/PropertyType. its impossible for the end user to add anything else caus its a dropdown select menu..

im trying to reduce the amount of space taken up on the search results page and I only need the PropertyType.. ie... it can be Apatment or Villa etc.. to be displayed.. and not the two parts before..

Thanxs for your help in advance.. Justin
Quote Reply
Re: [JustinS] Display only part of field.. In reply to
It a pretty simple solution then (only I don't have my Perl book at the moment)...

Basically you'd do something like:

$newtype = $rec{'your-field-name'};
$newtype =~ /take everything after the 2nd slash/;

Then your can print $newtype where ever you want it.

I'll look up the syntax for the "take everything after the 2nd slash" part later - unless someone else can bust it out for you.
Quote Reply
Re: [Watts] Display only part of field.. In reply to
Can any1 help me further.. Thanxs..
Quote Reply
Re: [JustinS] Display only part of field.. In reply to
I can't find my Perl for Dummies book (highly recommended BTW) so I'll guess...

Try this:
Code:
$newtype = $rec{'your-field-name'};
$newtype =~ /(\w+)$/;

print "$newtype";
The /(\w+)$/ instructs Perl to match (=~ //;) one or more (+) word-characters (\w) starting at the end ($) of the string and keep going until it hits a non-word character such as the backslash you are using in between words.

I don't have ActivePerl installed on my new system (it comes with the PFD book) so I couldn't test it. It may take some tweaking... I'll go buy another book this weekend - it's well worth the $20.

Last edited by:

Watts: Aug 17, 2003, 11:12 AM
Quote Reply
Re: [JustinS] Display only part of field.. In reply to
$rec{'your_field'} = "County/Town/Property";

($Country,$Town,$Property) = split(
/\//, $rec{'your_field'});

print
"$Country<br>$Town<br>$Property\n";

#### Print Slective fields only #########

print
"$Property";

Thanks,

Zeshan.

Last edited by:

zeshan: Aug 17, 2003, 6:43 PM
Quote Reply
Re: [zeshan] Display only part of field.. In reply to
Thanxs for the repy.. this makes sence.. just not sure how to incorparate into my site_html.pl

********************************

sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.
# This is the "short display" -- the list of records that are returned
# from a search.

my (%rec) = @_;

# create link to full display
$record_number = ((($nh - 1) * $db_max_hits) + $rec_count);

$rec{'Category'} = "Country/Town/Property";

($Country,$Town,$Property) = split(/\//, $rec{'Category'});


$long_url = $ENV{'QUERY_STRING'};
$long_url =~ s/\&nh=\d+//;
$long_url =~ s/\&mh=\d+//;

$long_url = "$db_script_url?$long_url&nh=$record_number&mh=1";

print "<TD>"; # do not remove this! It is necessary to make the records display properly

# Below is where you define what you want to appear for each record in the "short" display.
# You can make this whatever you want, and display as many fields as you would like.
# Choose which of the fields you would like for users to click on to reach the full display
# of records and use that field name in place of "Title" below.
#
# Be sure that you use <a href="$long_url"> for the link to your full record display.

# <-- Start of short display formatting -- >

print qq|


<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="8" align="left"><a href="$long_url" target="bottom">V$rec{'ID'}</a></td>
<td width="200" align="right">
|;
if ($rec{'Description'} eq "Studio") {
print qq|Studio|;
}
if ($rec{'Description'} eq "1 Bedroom") {
print qq|1Bed|;
}
if ($rec{'Description'} eq "2 Bedrooms") {
print qq|2Beds|;
}
if ($rec{'Description'} eq "3 Bedrooms") {
print qq|3Beds|;
}
if ($rec{'Description'} eq "4 Bedrooms") {
print qq|4Beds|;
}
if ($rec{'Description'} eq "5 Bedrooms") {
print qq|5Beds|;
}
if ($rec{'Description'} eq "6 Bedrooms+") {
print qq|6Beds+|;
}
if ($rec{'Description'} eq "Various Beds") {
print qq|Various|;
}
if ($rec{'Description'} eq "No Bedrooms") {
print qq|No Beds|;
}
print qq|
</td>
<td width="200" align="left">$rec{'URL'}</td>
<td width="100" align="right">$rec{'Contact Name'}E</td>
</tr>
</table>

<hr size="1" color="#008000">


|;

********************************



How do i get this bit in there.. print "$Property"; I did try and it just outputs "Property"..



I want to place it just after the.. $rec{'ID'} part above..



Thanxs in advance..
Quote Reply
Re: [JustinS] Display only part of field.. In reply to
I don't think you need this line;

$rec{'Category'} = "Country/Town/Property";

Then, I would use the same format as you used for $rec{'ID'}

Code:
print qq|


<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="8" align="left"><a href="$long_url" target="bottom">V$rec{'ID'}</a></td>
<td width="200" align="right">
<tr>
<td width="8" align="left"><a href="$long_url" target="bottom">V$Property</a></td>
<td width="200" align="right"> |;