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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| > > 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. |
| ||||
| 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 |
| Thread Tools | |
| Display Modes | |
|
|