Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I...do abstracts on text fields

Status
Not open for further replies.

Shrum

Programmer
May 17, 2002
122
US
I'm looking to take a large text field and I want to abstract it like so:

------------------
Title 1:
My Title

Abstract 1:
This is about a boy and his dog where they take a trip to...
------------------

The abstract is actually the description field but only X number of characters are shown.

Any one know how to do this?

=============================
Sean Shrum
Shrum Consulting
C.A.T.S.: Consulting: Programming: R/C Soaring:
 
Perhaps you can try:
SELECT RPAD(`abstract1`,X) FROM tablename;


"If you always do what you've always done, you will always be where you've always been."
 
if you search this forum you will find much neater ways of doing this than just the left option.
 
Do you want a constant number for X or do you want be break on a word or paragraph boundry ?.
A good and quick way would be to set up an abstract table whicch has only X characters in it. Alternativly make the large text in a sperate table and put the absctract int the main table.
 
Breaking after a word would be great since using LEFT() alone gets things like:

----------------------------
Little Timmie's dog chased after the cat who ran with ligh...
----------------------------

Creating another table just to have abstracts is just not efficent. Granted, if there's no way to do a word break based on a 1 table scenario, it's OK (for me, for now).

Ultimately, this'll be used to abstract out my weblog entries on my home page area and later on, my articles , project documentation, etc. on my site.

Using LEFT(`stringfield`, length) as `abstract` with a value of about 250 works out nice for me but, as I stated above, it can split a word in half. If there's a function that would allow me to break after a word, please let me know.

TIA

=============================
Sean Shrum
Shrum Consulting
C.A.T.S.: Consulting: Programming: R/C Soaring:
 
Initial thoughts would be..

1. If the text is longer than 250 bytes do this
2. look at byte 250
3. is it a space ?
3.1 use 250 as the break
3.3 work forward byte at a time until space found
3.4 Use this position as the break.

You could work backawards if you need to, you will end up with length lile 253, 270 etc depending on the length of the words etc.

 
sorry should have said, do this before you store the row in the table and keep the calualated length in the table as well
 
there was a topic about this just a few weeks ago with a nice solution but I can't find it any more :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top