Jump to content

Easily getting information back from php


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

Recommended Posts

  • Newbies

I'm a php developer not a filemaker developer. I have written a UPS Shipping Class in php that needs to return information about the shipment to filemaker. It could possibly need to put information in other tables besides the current one etc.

Whats the best way to go about this? Could I use FM evaluate? Should I send parameters to scripts? We also do alot of work with fx.php so I could theoretically use that but it seems very hackish to go outside filemaker and back in. It might not even work because its possible I could be using that record.

Which ever way you think is the best please include a little sample code if you don't mind. It would be appreciated. Keep in mind i'll be putting information in up to 10 fields in several different tables.

Thanks

Adam

Link to comment
Share on other sites

Hello Adam,

There are many ways to return data to FileMaker. Some things to consider include how the information is stored in your PHP code, for example, your class may have methods used for retrieving the various data or you may be returning an array. If you're making a web service call, it might be easiest to return XML.

You also have to decide if you're going to return all the data at once or if you're going to leave it in memory and come back for it. If you want to return all the data at once, you'll need to include a delimiter or use XML or some other method that allows you to parse out the data for each field.

Keep in mind that you can't choose which fields to set, you only get to return a value. The short of it is that you're most likely going to run a script. It might be possible to use FileMaker's auto-enter calc function to populate fields but that can get a bit hairy. It's funny that you suggested going around the horn with FX, we actually did a proof of concept with the same idea because we first needed to make a call to SQL server, etc. Anyway, a bit convoluted and it also then requires the entire web publishing engine, etc.

I think one of the easiest ways is to use an associative array where the keys are named the same as the fields that you want to set (this makes mapping simple). Let's say that your code returns an array with 2 bits of information that need to be set in FM, cost and estimated delivery date. And let's say the array looks like this:

Array

(

    [Cost] => 10

    [Estimated_Delivery_Date] => 1/25/2007

)




After your first call to the plug-in, this array will be in memory, you would then set the cost field using the following calc:




PHP_Execute( "echo $ups_data_arr['Cost'];" ; 1 )




And the estimated delivery date to:




PHP_Execute( "echo $ups_data_arr['Estimated_Delivery_Date'];" ; 1 )

NOTE: the second parameter for PHP_Execute is keepMemory, you must set it to 1 in order for this to work, otherwise your array will be destroyed.

Hopefully this helps. You could do the same type of thing with a DOM object and XPath where the DOM object remains in memory and you change your XPath query for each field.

We also experimented using ODBC against FileMaker via PHP but we had trouble getting it to work.

FileMaker does a nice job importing XML and this can be scripted so that's yet another option. You would save an XML file to disk and then run an import via script.

If you want to send me a copy of your file, I'm happy to take a look.

Link to comment
Share on other sites

  • Newbies

That was about what I was expecting. I was hoping to be able to do it basically from within php without having to build a massive script in filemaker but I guess that's probably the way we'll go.

Thanks for your help. Now you should write a magic plugin that makes the web publishing engine not so slow ;) I want mysql type speed :

Link to comment
Share on other sites

There’s a technique you can use to make this a bit more systematic. In a nutshell, you put the fields you want to set on a layout and then your script tabs through each field and sets them. The trick is not specifying the field for the set field script step. By not specifying the field, what ever field you’re in will get set. You then use Get ( ActiveFieldName ) to calculate the name of the current field which is then used as the key in your PHP code to get the correct value out of the array (or it could be an XML tag, etc.). When you've tabbed through all the fields, you're done. The nice thing is that you can use this type of script over and over, if you need to set different fields, just create a special layout with those fields on it.

Link to comment
Share on other sites

This topic is 6273 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
×
×
  • Create New...

Important Information

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