Finding a number in mysql database











up vote
-3
down vote

favorite












Using PHP, I am trying to find a record in a MySQL table where one of three columns may contain a part of a number that is searched for.



For example:
$number = 012321456789;



$get_results = mysqli_query($con,"
SELECT ID
FROM students
WHERE StudentTel LIKE '%$number%'
OR ParentTel LIKE '%$number%'
OR SponsorTel LIKE '%$number%'
");


The above lists just about the entire database as matching results.



Because numbers are captured in different ways, I cannot search for an exact match. A number may be captured like +270123456789, (27)0123456789, 0123456789-3 etc



I tried converting the number to a string, but same results.



I've also tried FIND_IN_SET($number,StudentTel) etc, but then I get no result - probably because there is no exact match.



Any assistance will be greatly appreciated.










share|improve this question
























  • For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
    – Funk Forty Niner
    Nov 8 at 11:33








  • 3




    The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
    – Jakub Matczak
    Nov 8 at 11:37








  • 1




    “The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
    – misorude
    Nov 8 at 12:04








  • 1




    LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
    – Sergiu Paraschiv
    Nov 8 at 12:38






  • 1




    “I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
    – misorude
    Nov 8 at 14:12

















up vote
-3
down vote

favorite












Using PHP, I am trying to find a record in a MySQL table where one of three columns may contain a part of a number that is searched for.



For example:
$number = 012321456789;



$get_results = mysqli_query($con,"
SELECT ID
FROM students
WHERE StudentTel LIKE '%$number%'
OR ParentTel LIKE '%$number%'
OR SponsorTel LIKE '%$number%'
");


The above lists just about the entire database as matching results.



Because numbers are captured in different ways, I cannot search for an exact match. A number may be captured like +270123456789, (27)0123456789, 0123456789-3 etc



I tried converting the number to a string, but same results.



I've also tried FIND_IN_SET($number,StudentTel) etc, but then I get no result - probably because there is no exact match.



Any assistance will be greatly appreciated.










share|improve this question
























  • For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
    – Funk Forty Niner
    Nov 8 at 11:33








  • 3




    The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
    – Jakub Matczak
    Nov 8 at 11:37








  • 1




    “The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
    – misorude
    Nov 8 at 12:04








  • 1




    LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
    – Sergiu Paraschiv
    Nov 8 at 12:38






  • 1




    “I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
    – misorude
    Nov 8 at 14:12















up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











Using PHP, I am trying to find a record in a MySQL table where one of three columns may contain a part of a number that is searched for.



For example:
$number = 012321456789;



$get_results = mysqli_query($con,"
SELECT ID
FROM students
WHERE StudentTel LIKE '%$number%'
OR ParentTel LIKE '%$number%'
OR SponsorTel LIKE '%$number%'
");


The above lists just about the entire database as matching results.



Because numbers are captured in different ways, I cannot search for an exact match. A number may be captured like +270123456789, (27)0123456789, 0123456789-3 etc



I tried converting the number to a string, but same results.



I've also tried FIND_IN_SET($number,StudentTel) etc, but then I get no result - probably because there is no exact match.



Any assistance will be greatly appreciated.










share|improve this question















Using PHP, I am trying to find a record in a MySQL table where one of three columns may contain a part of a number that is searched for.



For example:
$number = 012321456789;



$get_results = mysqli_query($con,"
SELECT ID
FROM students
WHERE StudentTel LIKE '%$number%'
OR ParentTel LIKE '%$number%'
OR SponsorTel LIKE '%$number%'
");


The above lists just about the entire database as matching results.



Because numbers are captured in different ways, I cannot search for an exact match. A number may be captured like +270123456789, (27)0123456789, 0123456789-3 etc



I tried converting the number to a string, but same results.



I've also tried FIND_IN_SET($number,StudentTel) etc, but then I get no result - probably because there is no exact match.



Any assistance will be greatly appreciated.







php mysql numbers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 12:02









Strawberry

25.6k83149




25.6k83149










asked Nov 8 at 11:29









user3270093

14




14












  • For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
    – Funk Forty Niner
    Nov 8 at 11:33








  • 3




    The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
    – Jakub Matczak
    Nov 8 at 11:37








  • 1




    “The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
    – misorude
    Nov 8 at 12:04








  • 1




    LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
    – Sergiu Paraschiv
    Nov 8 at 12:38






  • 1




    “I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
    – misorude
    Nov 8 at 14:12




















  • For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
    – Funk Forty Niner
    Nov 8 at 11:33








  • 3




    The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
    – Jakub Matczak
    Nov 8 at 11:37








  • 1




    “The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
    – misorude
    Nov 8 at 12:04








  • 1




    LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
    – Sergiu Paraschiv
    Nov 8 at 12:38






  • 1




    “I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
    – misorude
    Nov 8 at 14:12


















For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
– Funk Forty Niner
Nov 8 at 11:33






For example: $number = 012321456789; - That will not work with the leading zero, since it is being treated as an octal; wrap it in (single) quotes. Edit: the + in +270123456789 is also an issue and should also be wrapped in quotes, same goes for all of them.
– Funk Forty Niner
Nov 8 at 11:33






3




3




The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
– Jakub Matczak
Nov 8 at 11:37






The right way would to keep normalized phone numbers in database (without any special chars). If you really need original "formatted" numbers, then you might have separate columns with normalized versions just for search purpose.
– Jakub Matczak
Nov 8 at 11:37






1




1




“The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
– misorude
Nov 8 at 12:04






“The above lists just about the entire database as matching results.” - that can only be true if every single one of your records matches the number for at least one of the fields you are looking in; if that’s not the case, then your analysis of the problem must be wrong to begin with.
– misorude
Nov 8 at 12:04






1




1




LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
– Sergiu Paraschiv
Nov 8 at 12:38




LIKE '27021%' would work then and find all normalised phone numbers that start with 27021. Which wouldn't be possible if some of them would be stored as (27)021.
– Sergiu Paraschiv
Nov 8 at 12:38




1




1




“I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
– misorude
Nov 8 at 14:12






“I am searching for "2303205", and the first 3 matches I get are for the following numbers: "0712000061", "0849994189", "0766458485".” - then you must be doing your “searching” completely, absolute, totally wrong … None of those values contains 2303205 anywhere, so if you are searching with LIKE '%2303205%' you should not find anything at all here.
– misorude
Nov 8 at 14:12



















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%2f53206860%2ffinding-a-number-in-mysql-database%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%2f53206860%2ffinding-a-number-in-mysql-database%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

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff