Unix Technical Forum

Replace, Substitute, Delete

This is a discussion on Replace, Substitute, Delete within the MySQL General forum forums, part of the MySQL category; --> For years, I've been using FileMaker Pro to generate a staff photo gallery and staff phone directory from the ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:22 AM
John Kebbel
 
Posts: n/a
Default Replace, Substitute, Delete

For years, I've been using FileMaker Pro to generate a staff photo
gallery and staff phone directory from the same table of staff
information. I'm switching to PHP/MySQL for the year ahead. In STEP 1
below, I concatenate a name for the teacher/staff person image and in
STEP 3 I concatenate an XHTML table cell for the image and name. Steps 1
and 3 have been tested and work fine. I don't know how to accomplish
STEP 2 however. Suppose I start with a last name like De Long or Van
Schmidt? I wind up with de lonxx.jpg or van scxx.jpg for my image names.
I have a superstitious dread of putting spaces in Linux/Unix web file
names. Could someone suggest a way to replace the " " in imgName with
""?

STEP 1: Create the root of the image name
update staff set imgName = Lower(CONCAT(Left(last,6),Left(first,2)));

STEP 2:
How do I delete spaces in the imgName?

STEP 3:
update staff set webLine = CONCAT("<td><img src='images/",imgName,".jpg'
width='100' height='125'><br clear='all' />",first," ",last,"</td>");

Thanks in advance for your time spent in reading or responding.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:22 AM
Scott Haneda
 
Posts: n/a
Default Re: Replace, Substitute, Delete

>
> STEP 1: Create the root of the image name
> update staff set imgName = Lower(CONCAT(Left(last,6),Left(first,2)));
>
> STEP 2:
> How do I delete spaces in the imgName?
>
> STEP 3:
> update staff set webLine = CONCAT("<td><img src='images/",imgName,".jpg'
> width='100' height='125'><br clear='all' />",first," ",last,"</td>");
>
> Thanks in advance for your time spent in reading or responding.


Personally, I would move your html and string parse logic into php, rather
than in mysql, but that is up to you. If you want to do this in mysql..

SELECT REPLACE('De Long', ' ', '');
+-----------------------------+
| REPLACE('De Long', ' ', '') |
+-----------------------------+
| DeLong |
+-----------------------------+
1 row in set (0.00 sec)


You could also do..

SELECT REPLACE('De Long', ' ', '%20');
+--------------------------------+
| REPLACE('De Long', ' ', '%20') |
+--------------------------------+
| De%20Long |
+--------------------------------+
1 row in set (0.00 sec)


Which will url encode the space, which will allow perfectly for spaces in
filenames on a web server.
--
-------------------------------------------------------------
Scott Haneda Tel: 415.898.2602
<http://www.newgeo.com> Novato, CA U.S.A.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:22 AM
John Meyer
 
Posts: n/a
Default Re: Replace, Substitute, Delete

John Kebbel wrote:
> For years, I've been using FileMaker Pro to generate a staff photo
> gallery and staff phone directory from the same table of staff
> information. I'm switching to PHP/MySQL for the year ahead. In STEP 1
> below, I concatenate a name for the teacher/staff person image and in
> STEP 3 I concatenate an XHTML table cell for the image and name. Steps 1
> and 3 have been tested and work fine. I don't know how to accomplish
> STEP 2 however. Suppose I start with a last name like De Long or Van
> Schmidt? I wind up with de lonxx.jpg or van scxx.jpg for my image names.
> I have a superstitious dread of putting spaces in Linux/Unix web file
> names. Could someone suggest a way to replace the " " in imgName with
> ""?
>
> STEP 1: Create the root of the image name
> update staff set imgName = Lower(CONCAT(Left(last,6),Left(first,2)));
>
> STEP 2:
> How do I delete spaces in the imgName?
>
> STEP 3:
> update staff set webLine = CONCAT("<td><img src='images/",imgName,".jpg'
> width='100' height='125'><br clear='all' />",first," ",last,"</td>");
>
> Thanks in advance for your time spent in reading or responding.
>
>
>

In MySQL itself, check out the Replace() function:
http://dev.mysql.com/doc/refman/5.1/...nction_replace

In *nix (and by the way, a space really isn't that big of a deal as
people make it out to), you may want to do a perl script to find and
replace the spaces.

--
The NCP Revue -- http://www.ncprevue.com/blog

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com