Hi
I've got a Mysql table with numbers (table codes) and each number has and ID, I'm reading a file line by line using PHP (fopen),Each line has number, I want to match the number read in line with number on the table and then get the ID of the number, for example:
The line has the following number 0018697808976, And the table has the following numbers:
table codes:
number ID
001809 100
001869 101
0018X 102
00155 103
00153 104
002 105
The number on the line match with the number 001869 on the table, the number 0018697808976 should take ID 101.
Below part of the code that I'm using:
My problem is that the numbers on the table don`t have the same length, another problem It's that if the number on the line doesn't match any number on the table is has to take an ID (wild card), for example if the number on the linea is: 00187123456565, this number has to take ID 102.
Any Ideas?
I've got a Mysql table with numbers (table codes) and each number has and ID, I'm reading a file line by line using PHP (fopen),Each line has number, I want to match the number read in line with number on the table and then get the ID of the number, for example:
The line has the following number 0018697808976, And the table has the following numbers:
table codes:
number ID
001809 100
001869 101
0018X 102
00155 103
00153 104
002 105
The number on the line match with the number 001869 on the table, the number 0018697808976 should take ID 101.
Below part of the code that I'm using:
Code:
//$Numberx Contain part of the number to find out the ID
$Numberx=substr($Number,0,6);
$querye = "SELECT *, COUNT(ID) FROM codes WHERE codes.number LIKE '$Numberx' GROUP BY ID";
$resulte = mysql_query($querye) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($resulte)){
$count=$row['COUNT(ID)'] ;
}
if ($count == 1)
{
$queryf = "SELECT * FROM codes WHERE codes.number LIKE '$Numberx%'";
$resultf = mysql_query($queryf) or die(mysql_error());
while($row = mysql_fetch_array($resultf)){
$Idx=$row['Id'] ; //Get ID
$count=0;
}
}
Any Ideas?