If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Clip data in query??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-09, 18:20
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
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 %-)
Reply With Quote
  #2 (permalink)  
Old 04-16-09, 23:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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 ...

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-17-09, 10:20
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
And a thing of beauty it is

thanks again
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On