Jump to content

Archived

This topic is now archived and is closed to further replies.

creativkook

Returning only part of a text

Recommended Posts

If I wanted to return only part of a text entry in a database, for instance 50 words of a four paragraph entry as a sort of lead-in, is that possible?  I can't seem to find a query for it.  Does anyone know of one?

Share this post


Link to post
Share on other sites
Where do I place that?  Would it go after order by, where in the mysql query?  Could someone give me an example?  Thanks!

Share this post


Link to post
Share on other sites
Say that your query returns a field named "text" then you might do this:

while($row  = mysql_fetch_assoc($result))
{
  $shortened = substr($row['text'],0,50);
}

Now shortened is the first 50 chars of "text".

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.