Jump to content


Photo

Limit field length


  • Please log in to reply
3 replies to this topic

#1 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 06 May 2006 - 03:34 PM

How to limit a field's char length using PHP without changing anything to the db atributes?

#2 AndyB

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

Posted 06 May 2006 - 03:40 PM

When displaying data drawn from the database? When preparing data to add to the database? Please clarify what you want to do.
Legend has it that reading the manual never killed anyone.
My site

#3 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 06 May 2006 - 09:28 PM

I get a result from a database , for example "hello", and i put it in a variable, how can I limit the number of chars to 3? changing the variable value automatically to "hel" ?

#4 AndyB

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

Posted 06 May 2006 - 09:32 PM

You can use [a href=\"http://ca.php.net/manual/en/function.substr.php\" target=\"_blank\"]the substr() function[/a], or simply select the leftmost n characters of the database field in your query.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users