Gossamer Forum
Home : Products : DBMan : Customization :

Text formating

Quote Reply
Text formating
I have recently (today) setup dbman and I'd appreciate a little assistance please.

I intend using the database to store information obtained from a game. I have set the database up with as few fields as possible to facilitate the ease with which people can add information.

Here is an example of a record as saved on the db

Record Added
The following record was successfully added to the database: ID: 40
Kingdom Number: 12345
Kingdom Name: XYZ
Guild: None
Date: 18-Jun-2000
Description: XYZ Abc Number: 12345 Race: Sidhe Faith: Barnabas Guild: None Actions: 0 Networth: 370,899 Income: 385,785 Expenses: 715,480 Peasants: 56,761 Treasury: 14,610,151 Turns Used: 6614 Acres: 12,881 Wagons: 1500 Tents: 3000 Sacred Fields: 4060 Looms: 2714 Magick Circles: 1600 Nymphs: 0 Tuathas: 0 Selkies: 0 Spires: 0 Banshees: 0 Faeries: 20000 Green Green Green Green Green Elite Allies: 12346 12347
Validated: Yes

The problem is with the information that is stored in the description, I would like to be formated like this

XYZ
Abc
Number: 12345
Race: Sidhe
Faith: Barnabas
Guild: None
Actions: 0 Networth: 370,899
Income: 385,785
Expenses: 715,480
Peasants: 56,761
Treasury: 14,610,151
Turns Used: 6614 Acres: 12,881
Wagons: 1500
Tents: 3000
Sacred Fields: 4060
Looms: 2714
Magick Circles: 1600 Nymphs: 0
Tuathas: 0
Selkies: 0
Spires: 0
Banshees: 0
Faeries: 20000 Green
Green
Green
Green
Green
Elite

Allies: 12346 12347

Can it be done??? without having to have a separate field stored for each line.

Many thanks

Quote Reply
Re: Text formating In reply to
This probobly isn't the greatest solution, but if you put:
Code:
$rec{'Description'} =~ s/\n/<BR>/g;

(asuming the field name is "Description")

In sub html_record after the line:
Code:
my (%rec) = @_;


Then, press enter after each item in the Description field so they are
pushed onto a new line. Each occurance of a line break will then be converted
to a <BR> tag and you should get the list that you're after.

It relies on the information always being added in the correct fashion, but
it should get the job done. Although personally, I think it'd be best if you
had individual fields for each category...

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Text formating In reply to
Thank you for your suggestion. I tried it and it didn't appear to work.

I know that the information that is copied has some sort of formatting associated with it, as when you paste it into notepad it flows down the page as I would like it to in the description field. The information alos when pasted into Word shows as having carriage returns at the end of each row.

I would like to take these carriage returns and have the script insert a
so that the people who use the database have as little as possible to do and so <fingers crossed> fewer mistakes.

Quote Reply
Re: Text formating In reply to
That's exactly what that code does.

Did you put it after my (%rec) = @_;?

Also, make sure the green section matches that of the field name in your database:
$rec{'Description'} =~ s/\n/<BR>/g;

(remember, case is important, "description" is'nt the same as "Description")

If you're still having trouble, post your sub html_record so we can get a look at it.

Cheers,

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Text formating In reply to
Thank you I put it directly in the line after
my (%rec) = @_;?

and I copied and pasted
$rec{'Description'} =~ s/\n/<BR>/g;

so that the chance of error was reduced and yep it most certainly is 'Description' as opposed to description

ok sub html_record

I feel such and idiot. <mumbles>I posted it here in the sub html_record_form instead of the sub html_record.

It works wonderfully <hugs>
I'm female by the way in case your worried about the hug.

Quote Reply
What about file.db? In reply to
Hi, AstroBoy. Thanks for your help to deal with this problem. Right now I can show my data in text areas properly formatted. But there is still a remaining problem for me: when a record is added to default.db, all the line breaks are showed as two `` symbols. There is no problem with it when viewing data usinf dbman, but I have to use another script to view records, and this script shows these unwanted characters.
Do you know how to avoid these two unwanted symbols to be recorded? Thanks in advance!

Quote Reply
Re: What about file.db? In reply to
What sort of script are you using to view the records?
And how is it doing it?

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: What about file.db? In reply to
Fidel, this is how DBMan must save the records. There's no way around it.

The only thing I can suggest is that you use a file editor that's meant for programmers and do a global search-and-replace.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: What about file.db? In reply to
I thought maybe if the script was pulling the records from the .db file, you could run a simple regular expression over it to strip out the characters.

It depends on the script and what it's doing though...

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: What about file.db? In reply to
Yes, I suppose that would be possible. But it can't be changed within DBMan.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: What about file.db? In reply to
This is the script I use to show records. The reason to do that is because it allows to fully configurate the screen to show the records. I dont know hoy to make this script to show the records in cursos.db (generated by dbman) without ´´ characters instead
. Pls help!

$fields = 7; # Number of fields in each record
$filename = "./dbman/cursos.db"; # The database text file
$results = 90; # maximum number of results to display

&parse_form;

$searchstring = $FORM{'Clave'};

&open_file("FILE1","",$filename);


print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>... </TITLE>\n";

$counter = 0;

while (($line = &read_file("FILE1")) && ($counter < $results)) {
# split the fields at the | character
@tabledata = split(/\s*\|\s*/,$line ,$fields);
&check_record;
if ($found == 1) {
$counter++;
&print_record;
}

}
close(FILE1);

sub print_record {

print "
<TABLE WIDTH=\"80%\" CELLPADDING=10 CELLSPACING=10 BORDER=1 BGCOLOR=\"#FFFFCC\">\n";
print " <TR><TD ALIGN=\"Right\" VALIGN=\"TOP\" WIDTH=\"20%\"><Font face=\"Verdana, Arial, Helvetica\" Size=2 Color=#003399>Curso:</FONT></TD>
<TD WIDTH=\"80%\"><Font face=\"Verdana, Arial, Helvetica\" Size=2>$Curso</Font></TD></TR>

... html code, with fields showed by using $field (e.g. $Curso)

</TABLE>
<hr>

\n";
}

sub check_record {
# get the data from the record read from the file. $tabledata

$ID_Curso = $tabledata[0];
$Curso = $tabledata[1];
$Ponente = $tabledata[2];
$Descripcion = $tabledata[3];
$Fechas = $tabledata[4];
$Horario = $tabledata[5];
$Lugar = $tabledata[6];

#build the search line with all fields we want to search in
$searchline = $ID_Curso . " ". $Curso . " ". $Descripcion . " ". $Ponente . " ". $Lugar ;


#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;
}


}





sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}

@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}
}



sub open_file {

local ($filevar, $filemode, $filename) = @_;

open ($filevar,$filemode . $filename) ||
die ("Can't open $filename");
}

sub read_file {

local ($filevar) = @_;


<$filevar>;
}

sub write_file {

local ($filevar, $line) = @_;

print $filevar ($line);
}


Quote Reply
Re: What about file.db? In reply to
In sub parse_form under the line:
$value =~ tr/+/ /;

add the following line:
$value =~ tr/``/REPLACEMENT/g;

Change REPLACEMENT to whatever you'd like to replace the ``s with. If you wanted them to come ot as new lines for example, you would use:
$value =~ tr/``/<BR>/g;

If I understand correctly, that should solve the problem.

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: What about file.db? In reply to
I think the solution is more or less like you say, but the part of the script where the file default.db(in my exampls is named cursos.txt) is the foloowing:

while (($line = &read_file("FILE1")) && ($counter < $results)) {
# split the fields at the | character
@tabledata = split(/\s*\|\s*/,$line ,$fields);
&check_record;
if ($found == 1) {
$counter++;
&print_record;
}

I tried to place the line you suggested somewhere in this part, but I can't get the script running.

The routine parse_form reads the input of a form in html, and is used to get some keywords to perform a simple search.

I would appreciate if you could check the script again and say me where I should place the code for repaceing the ´´ characters.

Thanks!

Quote Reply
Re: What about file.db? In reply to
Ahhh, I think I see now...

The code needs to be added to sub print_record, before the your HTML, but instead of:
$value =~ tr/``/<BR>/g;

Use: $Descripcion =~ tr/``/<BR>/g; instead.

Set $Descripcion to the whichever field is returning ``s
($Curso, $Lugar, etc...)

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/