What is the way to search the database (mysql/php code) for the following entries:
- 123XX
- 123XY
- XYZ44
- 1X344
- 1Z344
- Z23YY
- The input letters are only X – Y – Z and the numbers from 0 to 9
They are all one number, which is (12344), so how can I show these results? The goal is to search for repeated entries.
Another example :
12XYY
X = 3,4,5,6,7,8,9,0
Y = 3,4,5,6,7,8,9,0
Provided that y is not equal to x or any apparent number (1,2)
And X is not equal to Y or any apparent number (1,2)
$number = "1XZYY";
$rnumber = str_replace(array('Y','X','Z'), "ـ", $number);
$lenNumber = strlen(5);
$duplicate = $mysqli->query("SELECT `number` FROM `listNumber` WHERE (length(`number`) = '$lenNumber' && `number` LIKE '%$rnumber%') OR (length(`number`) = '$lenNumber' && `number`LIKE '%$rnumber%')");
I tried many methods, but it was very slow in showing the results because I put the loop inside a loop to search for every number in the first loop
2
Answers
I would use PHP and occupy each digit into the correct position until I find a conflict. To prevent a double loop I use a dictionary helper object to hold values of X, Y and Z.
I understand you want to look for
12344
, but some of the digits may be been redacted and replaced with a random capital letter inXYZ
. For that, you can use a regular expression:Demo