Jump to content


Photo

Returning only part of a text


  • Please log in to reply
3 replies to this topic

#1 creativkook

creativkook
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 10 July 2006 - 09:38 PM

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?

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 July 2006 - 09:39 PM

substr
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 creativkook

creativkook
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 10 July 2006 - 09:43 PM

Where do I place that?  Would it go after order by, where in the mysql query?  Could someone give me an example?  Thanks!

#4 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 09:45 PM

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".
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users