Jump to content


Photo

Displaying a maximum amount of charachters


  • Please log in to reply
3 replies to this topic

#1 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 04 August 2006 - 11:14 AM

when a block of text is returned from a mysql query, is there any way of just displaying the first 40 charachters? so that it would look like this in the web page:

this is the first part of the returned res...

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 August 2006 - 11:18 AM

$query = "SELECT left(fieldname,40) FROM your_table_name ....";

or, select the whole thing but use the substr() function before displaying the text
Legend has it that reading the manual never killed anyone.
My site

#3 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 04 August 2006 - 11:23 AM

how would i use the substr() function?

#4 tvdhoff

tvdhoff
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 04 August 2006 - 11:45 AM

Try:

$content=$row["contentFromDB"];

$shortContent=substr($content,0,40);

Where '0' is the start character of the string ($content) you are using and '40' is the number of characters that will be outputted.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users