SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To all the PHP programmers out there,

    I have a question for you! I've been trying to limit a certain number of characters that the database returns for a certain column. I want users to be able to "preview" certain text, and not the entire thing. I understand that I should be using the LEFT function, but I can't seem to get it working. Does it have to be used within the SELECT function? When I've tried using it with the select function and then displaying it, it would display nothing. I don't know what the problem is. Can it be used without the select function? Thanks for any help!

    Regards,

    Leo Chan

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a small example:

    PHP Code:
    $result "SELECT name, email, LEFT(description, 50) as description FROM table_name"
    There ya go.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To further what Chris said if you don't want to it to cut off midword and let's say you wanted to grab the first 20 words from a field use

    PHP Code:
    $result mysql_query("SELECT SUBSTRING_INDEX(fieldname, ' ', 20) as shorttext from tablename"); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Crap! Beaten by a cat!

    To further the pain, his method is a more efficient version of a for() loop I usually use to accomplish the same thing. Dang.


Bookmarks

Posting Permissions

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