Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-05-2003, 07:06 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
summary

hi,
ok this is that I am trying to do. I am working on a thing for my site where a user can type an article, and submit it. then on the main page i want it to show the author, date etc., and only the first 100 words or so of their article is shown in the "summary"

anyone know how to pull only 100 words of something from a mysql database "text" field?

thanks,
Trevor
trevor is offline   Reply With Quote
Old 05-05-2003, 08:29 PM   #2 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
I don't know of a PHP mysql function that will only pull down a certain amount of text or data from a field, you either get the entire field or you don't. The best thing I can think of to do would be to use explode() to change the text into an array, limited to 100 words, then use implode() to turn it back into a string and print the string.
bdl is offline   Reply With Quote
Old 05-05-2003, 08:39 PM   #3 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
Code:
select
  x = cast(realField as char(100))
from
  tblY
didn't test it, and it mgiht give you a warning.. but anyway
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 05-06-2003, 04:59 AM   #4 (permalink)
randy
Registered User
 
randy's Avatar
 
Join Date: May 2003
Location: Gettysburg, PA
Posts: 7
randy is on a distinguished road
You could do what PostNuke does. When you go to post an article you get two boxes. One for summary text and one for extended text.

They can enter the first paragraph in the summary and rest in extended. That way you are pulling the summary from one field without trying to do a word or character count and you can just display both fields when someone wants to read the whole article.
randy is offline   Reply With Quote
Old 05-06-2003, 06:30 AM   #5 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Quote:
Originally posted by randy
You could do what PostNuke does. When you go to post an article you get two boxes. One for summary text and one for extended text.

They can enter the first paragraph in the summary and rest in extended. That way you are pulling the summary from one field without trying to do a word or character count and you can just display both fields when someone wants to read the whole article.
Interesting idea; I suppose it could also be done in such a way as to automatically grab the first 100 words (or 50 or 25, whatever) from the article and then store the article as two seperate fields in the db, rather than having to have two entry boxes for a summation and then the article.
bdl is offline   Reply With Quote
Old 05-07-2003, 07:40 AM   #6 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
ok yeah, i ended up just doing it the way postnuke does it...simpilest way i guess.....thanks all!
trevor is offline   Reply With Quote
Old 05-07-2003, 11:05 AM   #7 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
The way I would do it (not sure if it's the most efficient way) is to grab the whole article from the database, use explode to load it into an array, splitting on the whitespace. Then chop off all elements past the 100th, then use implode to turn the array back into a string.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 05-07-2003, 11:10 AM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
and don't forget to put the '. . . . .' after only if it is over 100 words
__________________
Mike
sde is offline   Reply With Quote
Old 05-07-2003, 09:50 PM   #9 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
I agree, you must put the '...', that's just proper writing skills.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:10 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting