Remove everything after string - sql

I have a table with a field that contains descriptions for items sold on my site.
In our infinite wisdom, when we first started the site, we pasted code for a Facebook Like button into the description, each just a little different, as it has product info in the link. We now have about 400 items with the code in it.
This is an example of what I'm dealing with:
-Whipped Up, Fluffy Chocolate-On-Chocolate Taste; A Lighter Way To Enjoy Chocolate
- 45% Less Fat < iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.oursite.com%2Findex.php%3Fmain_page%3Dproduct_info%26cPath%3D33_36%26products_id%3D106&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80"
scrolling="no" frameborder="0" style="border:none; overflow:hidden;
width:450px; height:80px;" allowTransparency="true">< /iframe>
I want to remove the <iframe and everything past it. I have been looking around for examples using REPLACE and/or LEFT, but can't find what I need, as I am not very well versed in SQL language.
It will always be at the end of the products_description field, so I don't need to worry about saving anything past it, only before it.
The best I can come up with is
SELECT LEFT(REPLACE('<iframe%','<iframe%',' '),0)
but that doesn't seem to work.
Thank you for any help you can offer on this, as it will take me much less time than editing each description.
UPDATE: Still haven't found an answer, after trying many variations of what has been suggested. It runs, but makes no edit to the column.
I also tried this, after finding it on another site. The same, but thought it might give someone an idea of how to proceed:
select left(`products_description`,instr('<iframe',`products_description`)-1) FROM products_description

SELECT
trim( -- trim removes spaces before and after given string
left(
'some text < iframe',
locate('< iframe', 'some text < iframe') - 1
)
);
For better understanding i did not removed space between < and iframe.
You may also take a look at this thread:
Remove HTML tags from record
but this is discussion about removing tags only, and keeping <tag>text</tag> between tags. Anyway it will for for you, because you have nothing between <iframe> and </iframe>.

REPLACE('<iframe%','<iframe%',' ') will give you just ' ' - it searches first argument for second argument and replaces it with third.
LEFT(somestring, 0) will give you 0 characters string

Try this:
select substr(your_raw_string, 0, instr(your_raw_string, '<iframe') -1)
from your_table

Related

HTML not rendering through EJS

so basically I have a bunch of HTML strings in a MySQL table and I am trying to display then through EJS.
For instance, I have a string that looks like this is a link with some <code>code</code> next to it. In my code I try to display it in that way.
<%- listOfStrings["myString"] -%>
However, as you probably guessed when reading the title, the string seems to be escaped when displaying on the screen.
What's even weirder to me is that I have two tables with such strings, and it works for the first one, while it doesn't for the second one. One difference though, is that the first one is hardcoded, while the second one can be edited through some tool on my website. Encoding is utf32_unicode_ci for both tables, if that matters.
For debugging purposes I tried to store the aforementioned strings in a js variable and display them in the console: then it seems like <and > characters are all escaped for some reason. Is there an explanation to this behavior, and if so how to fix it so that HTML renders correctly?
Thanks for your help!
You can try it :
<%=listOfStrings["myString"]%>

Show content based on whether the user has certain tag in Mailchimp

I went through the Merge Tags here and here, but couldn't figure out the syntax that would allow me to show content based on whether the user has certain Tag or not.
Help?
My goal in case it helps:
User subscribes, and is queued for a welcome mail one day later. In meantime that user may get tagged (my way of segmenting them), and so, the next day when that user receives the welcome mail, the content needs to be catered based on the tag that user got.
Got a response from their support saying
merge tags do not work with Tags just yet
here's the whole thing:
While we do have conditional merge tags available, I'm afraid we do
not have any that would work with Tags. To be transparent, Tags were
recently added a few months ago, and there are some features in our
application that has not updated to work with Tags just yet.
Because conditional merge tags do not work with tags yet, the best
option would be to create multiple automations and send them out based
on each tags. If you do it that way, you'll be able to target those in
specific tags with specific content
Dug a little deeper from the first link. There is another link Use Conditional Merge Tag Blocks which contained the below code:
Name
IF-ELSE
Definition
Use ELSE to indicate alternative content to display if the *|MERGE|* tag value is false.
Example
*|IF:MERGE|* content to display *|ELSE:|* alternative content to display *|END:IF|*
Name
ELSEIF
Definition
Use ELSEIF to specify a new *|MERGE|* tag to be matched against if the first *|MERGE|* tag value is false.
Example
*|IF:TRANSACTIONS >= 20|* Enjoy this 40% off coupon! *|COUPON40|*
*|ELSEIF:TRANSACTIONS >= 10|* Enjoy this 20% off coupon! *|COUPON20|*
*|ELSE:|* Enjoy this 10% off coupon! *|COUPON10|* *|END:IF|*
More examples with definitions can be found here.
Hope this is the answer you were after.

Best way to add target ='_blank' for href in a string using UDF

I've got data in sql server 2012 that contains text with links test with out target i need to add target for the string data. I need to create a User defined function for that. Does any one have any sample code for this.
Example text -
If you've ever thought one of your text message threads was so good it deserved to be published, you may be on to something.view. njkhj In future iterations, users will be able to post .<br><br>You may update your email address at any time by going to sdffsd. Our whole goal is to have the reader go through an entire narrative arc in five minutes and consume it in a way that's native to mobile," says Gupta go to sdfsdf which is one of my favorite books, is told as letters back and forth between the two main
I think a simple replace would do the trick
Declare #String varchar(max) = 'Some large text with a link to content'
Select Replace(#String,' href=','_target="blank" href=')
Returns
(No column name)
Some large text with a <a _target="blank" href="test/test">link</a> to content
We can also use
SELECT REPLACE(text,'<a','<a target="_blank" ');
Go

Dojo Filtering Select Filtering

Is there a way to include the entire value in the filtering search? For example, searching “123″ would return the value “Test 123″. By default, the control only filters starting with the first character.
I tried modifying the queryExpr property mentioned here, but nothing seemed to work for me. Thanks for any tips.
I realise this is 2 years ago but I'm just answering in case someone else comes along looking!
You can specify the queryExpr like this:
<xe:djFilteringSelect id="djFilteringSelect1" value="#{viewScope.myvalue}" autoComplete="false">
<xe:this.queryExpr><![CDATA[${javascript:"*$\{0}*"}]]></xe:this.queryExpr>
<xp:selectItems id="selectItems1" value="#{myBean.mySelectItems}"/>
</xe:djFilteringSelect>

onCLick getElementById().innerHTML doesn't work repeatedly?

here is the page on which the problem lies: www.hodaradesign.com/vis-vertical2.html
I tried to enter code here but the site wouldn't let me. So go to the page and view source. There is a list of 10 inputs. three dont work even though all 10 inputs use the same code.
can anyone help me out?
Thank you
In the HTML code you use for "Light n Life" there is a sentence: "LNL's founder wanted a logo [...]". It contains a single quote ("LNL's") which ends the string. You have to escape single quotes.