Jump to content

Playing with PHP API, data type issue ?


draad
 Share

This topic is 2833 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hello everyone.

 

I'm plyaing for the first time with filemaker PHP API, and, even if I succeed on doing a basic newFindRequest (), I'm stuck on something that must be very simple but I can't get working.

 

 

I have a layout called "Php Ipv4 Blocks" linked to a table that keep tracks of IPs as long and the country associated to thoses IPs. My table structure looks like this :

   

id                         :  unique id   (number)

country_id           :  id of a country   (number)

integer_ip_from   :  starting value of ip range as long   (number)

integer_ip_from   :  ending value of ip range as long   (number)

 

 

In my php script, I transform an ip to a long value and then, I try to perform a newFindRequest() where 

integer_ip_from <= ip as long

integer_ip_to     >= ip as long

 

 

I use this function to transfor IP to long :

$longIp  =  printf("%un", ip2long($IP));

If I try with a random ip, for exemple : 173.176.47.188

Converted as long I find this value :    2914004924

 

So now, I try to perform my find :

function getCountryForIp ($IP){ 
$longIp  =  printf("%un", ip2long($IP));


$findCommand = $GLOBALS["fm"]->newFindCommand("Php Ipv4 Blocks");
$findCommand->addFindCriterion("integer_ip_from", '<=' . $longIp);
$findCommand->addFindCriterion("integer_ip_to"  , '>=' . $longIp);


$result   = $findCommand->execute();


if (FileMaker::isError($result))
{
echo $result->getCode();
echo $result->getMessage();
echo "No country found";
return false;
}
else
{
$record  = $result->getFirstRecord();
$country = $record->getField("country_id");
echo "country id " . $country;
return true;
}

This will return me : 401 No records match the request.

 

 

Note that if for testing purpose I replace my var $longIp and input the long value directly I find my record:

$longIp  =  2914004924; //printf("%un", ip2long($IP));

Can you guys help me on this issue ?

Thanks.

Link to comment
Share on other sites

I believe you should store the field for searching as FileMaker Number type( the output of ip2long() ) without the linebreak.

Link to comment
Share on other sites

This topic is 2833 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.