Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    124

    Unanswered: Clip data in query??

    Is there a way to shorten the data returned by a query? I have a field with a image file name i.e. "image.jpg", what I want to display on the php page is just the "image" part. I'm wondering id there is a way to strip off the last four characters (.jpg) of the field?

    Nick %-)

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    to answer your specific question, to strip off the last four characters, you could try a combination of nested functions involving LEFT and LENGTH - 4

    but mysql has an even neater function

    to remove the "extension" portion of a file name, and assuming that the file name contains only one "dot" (period), the following will work nicely whether the extension is 3 characters or four (e.g. oldnickj.jpeg versus oldnickj.jpg)

    SELECT SUBSTRING_INDEX(filename,'.',1) AS image ...

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2009
    Posts
    124
    And a thing of beauty it is

    thanks again

Posting Permissions

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