Results 1 to 2 of 2

Thread: Help with limiting text from DB

  1. #1

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Help with limiting text from DB

    Hey,

    I have developed a simple from system that allows users to input some comments. This all works fine, however when I try to retrieve the comments I only want to display 100 characters.

    I am new to PHP, but was wondering if there is a string function that will let me take the data from a table in my database and then only display 100 characters followed by "..." afterwards.

    Also I have thought of a potential problem... if someone enters less than 100 characters I only want to show the amount they have entered.

    can anyone help?
    Living a Lie, Timmy

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help with limiting text from DB

    This is something that should be done in your query rather than the application code. If you are always going to truncate the query result, it makes no sense to have to return all of the data from the database server.

    If you're using MySQL, have a look at the MySQL String Functions—in particular, LEFT() will do what you need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width