[FX.php List] [OFF] API Equivalent for Grabbing RECID

Bob Patin bob at patin.com
Wed Apr 2 16:47:57 MDT 2008


Jonathan,

I do it by creating a calc field called "recid" and then I grab that;  
here's some code:

<?php

require('include/db.inc.php'); // this has my database info in it

$postsFind = $blogDB -> newFindAllCommand('posts');
$postsFind->addSortRule('timestamp',1,FILEMAKER_SORT_DESCEND);
$posts = $postsFind->execute();
if(FileMaker::isError($posts)){
	header ("Location: index.htm"); // this redirects if my FM server  
doesn't respond for some reason
}

// this pulls out the records

$postsArray=$posts->getRecords();
foreach($postsArray as $post){
	$body = html_entity_decode(nl2br($post->getField('post_preview')));
	$post_preview = html_entity_decode(nl2br($post- 
 >getField('post_preview')));
	$d_created = $post->getField('d_created');
	$is_different = $post->getField('is_different');
	$recid = $post->getField('recid');
	$title = $post->getField('title');
}

?>

So as you can see, I'm doing a FINDALL, and then this line

$postsArray=$posts->getRecords();

gets the results and puts it into $postsArray, after which you use a  
FOREACH to cycle thru the found set. As you can see, I retrieve my  
field called "recid;" I'm sure there's another way to do it, but I  
like this method, which I also use in FX.php, rather than using the  
explode command. Just seems easier to me.

Hope this helps; I read the Stephen Knight book to get a grip on the  
API, and it walks you through it very well. I found it very useful,  
and the code I write is very trim, compared to what FMServer 9  
generates in the Site Designer (I forget what it's called).

Here's the contents of db.inc.php:

<?php
require_once('FileMaker/FileMaker.php');

$DB_HOST = 'xxx.xxx.xxx.xxx';
$DB_NAME = 'dbname';
$DB_USER = 'username';
$DB_PASS = 'password';

$blogDB = new FileMaker($DB_NAME, $DB_HOST, $DB_USER, $DB_PASS);
?>



Best,

Bob Patin
Longterm Solutions
bob at longtermsolutions.com
615-333-6858
http://www.longtermsolutions.com
Member of FileMaker Business Alliance and FileMaker TechNet

   CONTACT US VIA INSTANT MESSAGING:
      AIM or iChat: longterm1954
      Yahoo: longterm_solutions
      MSN: tech at longtermsolutions.com
      ICQ: 159333060

--------------------------
Contact us for FileMaker hosting and programming for all versions of  
FileMaker
PHP • CDML • Full email services • Free DNS hosting • Colocation •  
Consulting


On Apr 2, 2008, at 5:12 PM, Jonathan Schwartz wrote:

> Hi Folks,
>
> I'm helping a colleague with their first PHP project, but they are  
> using the FMP API.
>
> I can't make heads or tails of the API interface.
>
> Can someone clue me in how to grab the recid after creating a  
> record? I need it to edit the record later in the session.
>
> The existing code for creating the record looks like this:



More information about the FX.php_List mailing list