Author Topic: Need Help Deleting Characters  (Read 3576 times)

0 Members and 1 Guest are viewing this topic.

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Need Help Deleting Characters
« on: April 12, 2011, 11:37:35 AM »
I'm using CSVSearch for use on a real estate web site. I get new data updated from the MLS daily. One of the fields is the MLS number of the listing, with the field name of [MLS #] which is a unique 6 digit number.

My problem is trying to link the photo image on the return page. The image is stored on the MLS's web server (not mine), and one of the sub-directories is the last 3 characters of the MLS number. For example, if the MLS number was 123456 the image would be found as

http://TheMLSwebsite.com/images/456/123456.jpg

If it didn't have that 3 digit sub-directory, it would be easy to set up the table on my template to display the photo as:

<image scr=http://themlssite.com/images/[[MLS #]].jpg>

So, how would I set up my template to make that sub-directory [[MLS #]] minus the first three characters?

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Need Help Deleting Characters
« Reply #1 on: April 12, 2011, 12:48:39 PM »
Hi webhog,

This should actually be moved to the CSV scripts section, not the forum script section, but I can help you out anyway and maybe EZ can move it later.

You actually need to use javascript to do this. It isn't hard, so here is what you do:

First as a good practice, I would not make one of your fields include a special character like "#". Use MLS_Number instead. Also, do not put spaces in your field names, that can cause significant issues.  Here is your js:

Code: [Select]
<script>
var str = "[[MLS_number]]"
var subdirectory = str.slice(3);
document.write("<img src=http://www.sitename.com/images/" + subdirectory + "/[[MLS_number]].jpg");
</script>

That will cut the MLS number between the 3rd and 4th number and write it to a variable. The js also writes the img tag for you.

Jason
« Last Edit: April 12, 2011, 12:59:38 PM by Jason »
Founder of www.slipdex.com

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Re: Need Help Deleting Characters
« Reply #2 on: April 12, 2011, 01:32:01 PM »
Jason -

Thank you VERY MUCH for your help.

I suspected that spaces and the special character would cause a problem - and it does. Here's what I get:



My problem is that, that field is automatically named [MLS #] from my daily upload from the MLS. So even if I rename it, the file gets overwritten each night. So is there some way to rename that field name on the template before your script creates the image tag?

Marty

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Need Help Deleting Characters
« Reply #3 on: April 12, 2011, 02:48:14 PM »
Marty,

That is a very interesting issue you have there....

The content you pasted there though looks like there is a problem with the syntax, which I may have made. Do you mind sending me a link to that page and I would be more than happy to look at your source and see if I can hash it out.

On the side of that, is there no way to get that field renamed by the source file?

In any event, I am 90% sure that the issue you have there is syntax that might be correctable. so if I can get a link I might be able to fix it.

Jason
Founder of www.slipdex.com

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Re: Need Help Deleting Characters
« Reply #4 on: April 12, 2011, 03:08:19 PM »
Yea - Major syntax error on my part. I forgot the beginning <script> tag - duh.

Now I get just the broken image icon. It has the hard coded portion of the image tag, but the variable parts (subdirectory & JPG name) are nonexistent.

Here's my practice page:

http://homesalesfla.com/cgi-bin/csvsearch/csvsearch2.pl?Status=A&Subdivision=48&order_by=DOM&order=321


Marty

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Need Help Deleting Characters
« Reply #5 on: April 12, 2011, 03:14:29 PM »
Hey Marty,

Try this:

Code: [Select]
<script>
var str = "[[MLS #]]"
var subdirectory = str.slice(3);
document.write("<img src=http://www.brevardmls.com/brv/thjpg/" + subdirectory +" /[[MLS #]].jpg");
</script>

I removed the simgle quotes completely.

Going for a walk with the wife and dogs, be back in 30 minutes.

Jason
Founder of www.slipdex.com

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Re: Need Help Deleting Characters
« Reply #6 on: April 12, 2011, 04:01:02 PM »
Getting close!

It's writing the sub-directory with the 3 digits - just need to get the [[MLS #]].jpg part to show up.

Marty

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Re: Need Help Deleting Characters
« Reply #7 on: April 12, 2011, 04:07:07 PM »
Now I got it - I moved the quote mark over (the one next to the "+" after "subdirectory"):

Code: [Select]
<script>
var str = "[[MLS #]]"
var subdirectory = str.slice(3);
document.write("<img src=http://www.brevardmls.com/brv/thjpg/" + subdirectory + "/[[MLS #]].jpg");
</script>

Thanks a lot - I owe ya a beer - or two!

Marty

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Need Help Deleting Characters
« Reply #8 on: April 12, 2011, 04:09:36 PM »
Hi Marty,

Yah I just caught that. Sorry about that, typing with no testing... I'm a bit rusty. Glad you got it worked out.

Jason
Founder of www.slipdex.com

Offline EZ

  • Hero Member
  • *****
  • Posts: 1081
    • Babelnotes.be
Re: Need Help Deleting Characters
« Reply #9 on: April 12, 2011, 08:00:24 PM »
Give the man a Belgian beer!  :-)

Offline webhog

  • Newbie
  • *
  • Posts: 8
    • Mr Palm Bay
Re: Need Help Deleting Characters
« Reply #10 on: April 12, 2011, 08:05:07 PM »
Hope he likes HomDepot.

Marty

Offline EZ

  • Hero Member
  • *****
  • Posts: 1081
    • Babelnotes.be
Re: Need Help Deleting Characters
« Reply #11 on: April 13, 2011, 02:31:57 AM »
Send him a West-Vleteren  ;-)