Gossamer Forum
Home : Products : DBMan : Customization :

Splitting a single field into two columns - Character Count

Quote Reply
Splitting a single field into two columns - Character Count
Hey there, all. Okay, I think I've got a good one for y'all. I have a text field in a database that has the potential for getting pretty long and what I'd like to do, basically, is have the database split THAT FIELD into two different columns when it displays html_record_long.

So, the process, in english, I'm sure would go something like:
  1. Count the number of characters in a field
  2. Divide that number by two to get 'x'
  3. Find out what the 'x'th character in the field is
  4. If 'x' is not equal to a blank space then x = x+1 (loop so that the database doesn't put a column break in the middle of a word)
  5. Once it 'x' becomes equal to a blank space, print the table tags for closing and starting a new column.


Problem is, I'm really not sure how to do this.. But it seems like it would be a fairly simple process... Nothing more than simple math, really. I just don't have a single idea as to how to get a count of the number of characters in a specified field. Any ideas anyone? Many thanks in advance. Cheers!
Quote Reply
Re: [wretchedhive] Splitting a single field into two columns - Character Count In reply to
It may be easiest to just make the field a textarea rather than text field. Here is a thread reference which may help you with calculating the field length:

Limiting character display in short/long mod

Thread reference: http://gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002783.html
Topic: short/long display mod
Scouser April 26, 2000

Question:
Is there someway of cutting descriptions that are shown in the short display to say 50 letters.

Response:
If you want just 50 characters of a field to show in the short display,

after: my (%rec) = @_;

add code:

if (length($rec{'Description'}) >50) {
$rec{'Description'} = substr($rec{'Description'},0,50);
$rec{'Description'} .= "...";
}

But I'm not sure what modifications would be needed to have it take the remaining number of characters and place them into another field.

Another thread you may want to check out is:

Subject Sub Splitting a Field
bullivtm 30-Jan-01
Thread: http://gossamer-threads.com/p/124536

If the URLs are not correct search by the topic subject or user.

Hope this helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/