Wrong flag setting for SUBSTRING_INDEX operator











up vote
0
down vote

favorite












I compiled a query that chooses a link from the 'ss' column:



'ss' column:



<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>


Here is my SQL:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-3 ),'.jpg" s',1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-2 ),'.jpg" s',1 )
UPDATE post SET still3 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-1 ),'.jpg" s',1 )


I refer to the first link using the -3 flag. When the number of links is three, everything works fine. But when there are fewer of them (there cannot be more than three of them) - an incorrect result is issued. Is there an alternative to the first link? (for cases when links, only 2 for example).



Here is one and non-working options that I went through:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',1 ),'.jpg" s',-1 )


I can not understand why this option does not work.



UPD:



Okey, here is a simple query that I was looking for:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',1 ),'nk"><img data-src="',-1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',2 ),'nk"><img data-src="',-1 )
...


However, I still did not understand the recursive MySQL logic.










share|improve this question
























  • What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 17 at 19:54












  • I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
    – noobsaibot
    Nov 17 at 19:56










  • The above links are in the database, in the field "xfields"... translation difficulties
    – noobsaibot
    Nov 17 at 20:05










  • Why not treat it as xml and extract the data using built in xml handling/xpath?
    – Caius Jard
    Nov 17 at 20:09










  • I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
    – noobsaibot
    Nov 17 at 20:18















up vote
0
down vote

favorite












I compiled a query that chooses a link from the 'ss' column:



'ss' column:



<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>


Here is my SQL:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-3 ),'.jpg" s',1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-2 ),'.jpg" s',1 )
UPDATE post SET still3 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-1 ),'.jpg" s',1 )


I refer to the first link using the -3 flag. When the number of links is three, everything works fine. But when there are fewer of them (there cannot be more than three of them) - an incorrect result is issued. Is there an alternative to the first link? (for cases when links, only 2 for example).



Here is one and non-working options that I went through:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',1 ),'.jpg" s',-1 )


I can not understand why this option does not work.



UPD:



Okey, here is a simple query that I was looking for:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',1 ),'nk"><img data-src="',-1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',2 ),'nk"><img data-src="',-1 )
...


However, I still did not understand the recursive MySQL logic.










share|improve this question
























  • What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 17 at 19:54












  • I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
    – noobsaibot
    Nov 17 at 19:56










  • The above links are in the database, in the field "xfields"... translation difficulties
    – noobsaibot
    Nov 17 at 20:05










  • Why not treat it as xml and extract the data using built in xml handling/xpath?
    – Caius Jard
    Nov 17 at 20:09










  • I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
    – noobsaibot
    Nov 17 at 20:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I compiled a query that chooses a link from the 'ss' column:



'ss' column:



<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>


Here is my SQL:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-3 ),'.jpg" s',1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-2 ),'.jpg" s',1 )
UPDATE post SET still3 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-1 ),'.jpg" s',1 )


I refer to the first link using the -3 flag. When the number of links is three, everything works fine. But when there are fewer of them (there cannot be more than three of them) - an incorrect result is issued. Is there an alternative to the first link? (for cases when links, only 2 for example).



Here is one and non-working options that I went through:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',1 ),'.jpg" s',-1 )


I can not understand why this option does not work.



UPD:



Okey, here is a simple query that I was looking for:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',1 ),'nk"><img data-src="',-1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',2 ),'nk"><img data-src="',-1 )
...


However, I still did not understand the recursive MySQL logic.










share|improve this question















I compiled a query that chooses a link from the 'ss' column:



'ss' column:



<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>
<a href="#" target="_blank"><img data-src="https://asd.com/123.jpg" srcset="https://asd.com/234.jpg"></a>


Here is my SQL:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-3 ),'.jpg" s',1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-2 ),'.jpg" s',1 )
UPDATE post SET still3 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',-1 ),'.jpg" s',1 )


I refer to the first link using the -3 flag. When the number of links is three, everything works fine. But when there are fewer of them (there cannot be more than three of them) - an incorrect result is issued. Is there an alternative to the first link? (for cases when links, only 2 for example).



Here is one and non-working options that I went through:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'nk"><img data-src="',1 ),'.jpg" s',-1 )


I can not understand why this option does not work.



UPD:



Okey, here is a simple query that I was looking for:



UPDATE post SET still1 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',1 ),'nk"><img data-src="',-1 )
UPDATE post SET still2 = SUBSTRING_INDEX( SUBSTRING_INDEX( ss,'.jpg" s',2 ),'nk"><img data-src="',-1 )
...


However, I still did not understand the recursive MySQL logic.







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 8:07

























asked Nov 17 at 19:43









noobsaibot

328




328












  • What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 17 at 19:54












  • I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
    – noobsaibot
    Nov 17 at 19:56










  • The above links are in the database, in the field "xfields"... translation difficulties
    – noobsaibot
    Nov 17 at 20:05










  • Why not treat it as xml and extract the data using built in xml handling/xpath?
    – Caius Jard
    Nov 17 at 20:09










  • I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
    – noobsaibot
    Nov 17 at 20:18


















  • What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 17 at 19:54












  • I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
    – noobsaibot
    Nov 17 at 19:56










  • The above links are in the database, in the field "xfields"... translation difficulties
    – noobsaibot
    Nov 17 at 20:05










  • Why not treat it as xml and extract the data using built in xml handling/xpath?
    – Caius Jard
    Nov 17 at 20:09










  • I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
    – noobsaibot
    Nov 17 at 20:18
















What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 17 at 19:54






What are you trying to parse from the html? Or what data do you need? i advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 17 at 19:54














I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
– noobsaibot
Nov 17 at 19:56




I need this link: asd.com/123.jpg in my still1, still2,, still3 columns.
– noobsaibot
Nov 17 at 19:56












The above links are in the database, in the field "xfields"... translation difficulties
– noobsaibot
Nov 17 at 20:05




The above links are in the database, in the field "xfields"... translation difficulties
– noobsaibot
Nov 17 at 20:05












Why not treat it as xml and extract the data using built in xml handling/xpath?
– Caius Jard
Nov 17 at 20:09




Why not treat it as xml and extract the data using built in xml handling/xpath?
– Caius Jard
Nov 17 at 20:09












I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
– noobsaibot
Nov 17 at 20:18




I have not enough experience for this, besides, I am dealing with encrypted IonCube code... A small update of stills1, stills2, stills3 is all I need. I’m sure I’m missing out on some little detail in the SQL request.
– noobsaibot
Nov 17 at 20:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354897%2fwrong-flag-setting-for-substring-index-operator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354897%2fwrong-flag-setting-for-substring-index-operator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin