Search only a random part within a select mysql code

Asked

Viewed 67 times

1

The problem is this, I have the code concatenated, I need to see this code concatenated if part of it is in the table, ie when joining field 1 and field 2 with PHP, before searching in the table, a variable brings me this pre-programmed, I will have the code:

212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0b7ab992312978885b4cd079a9d9ea5c955fce646635fa2e2n3fbrqv345d4231qepklnt3i73

I have so this code, I need to put this on like for him to bring me this code by finding them in two different fields, namely in field to from my table I have

212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0

and in the field B I have

b7ab992312978885b4cd079a9d9ea5c955fce646635fa2e2n3fbrqv345d4231qepklnt3i73

and in the variable I have

212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0b7ab992312978885b4cd079a9d9ea5c955fce646635fa2e2n3fbrqv345d4231qepklnt3i73

I have to search this in Mysql and bring me these two field, this is possible?

EDIT

Yeah, it took me a while, but I thought Basic with concat_ws

select * from tabela where concat_ws('',campo1,campo2) 
like '%n3fbrqv345d4231qepklnt3i73212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0b7ab992312978885b4c%';
  • 1

    What is the type of column?

  • @Ricardo puts, I think I gave this mole so, I think élongtext, does not work if it is longtext?

  • I will check, as I did not know what type I did for CHAR and VARCHAR, Aja edit my reply.

  • I edited my answer but haven’t found out if it works with longtext

  • I figured this would work - select * from table Where Concat(field1, field2) like "%212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0b7ab992312978885b4cd079a9d9ea5c955fce646635fa2e2n3fbrqv345d4231qklnt3i73%" - but it doesn’t work

2 answers

1


If the type of column is: CHAR or VARCHAR is sure that the LIKE will work perfectly:

SELECT * FROM `tabela` WHERE campo LIKE “%n3fbrqv345d4231qepklnt3i73%”

Also try using the string function INSTR:

SELECT * FROM `tabela` WHERE INSTR("212e5a8817f6f40da398b9baddddecd28abff2df24b6816fabdf2ff4e64dfd00b192d7f0a2bed8b0b7ab992312978885b4cd079a9d9ea5c955fce646635fa2e2n3fbrqv345d4231qepklnt3i73", “%n3fbrqv345d4231qepklnt3i73%”);

0

Checked if the problem is not case sensitive?

To solve this just add the LOWER, that will turn everything into tiny.

$busca = strtolower($busca);
$resultado = $mysqli->query("SELECT * FROM tabela WHERE LOWER(campo) LIKE '%". $busca . "%'");
  • no, it’s no cases, it’s random code with large and small letters even, but I think it might be the fact that the spoke longtext

Browser other questions tagged

You are not signed in. Login or sign up in order to post.