Jump to content
Sign in to follow this  
Guru Salem

Get records from 2 filemaker tables from php

Recommended Posts

Please find the below code that im trying to display the company name and also product name,

Here both tables are separable. when im get the company details its working fine.. when i try to get the product table records based on the company id, I found the error "Fatal error: Call to undefined method FileMaker_Error::getRecords()"

Please help to resolve this issue


//Get all company details from company layout (company table)

$findCommand = & $fm->newFindAllCommand('company');

$result = $findCommand->execute();

$records = $result->getRecords();



//dispaly the company

foreach($records as $record) {

    echo $record->getField('name')

    echo $cid = $record->getField('id');



    //get products from procut layout base on the company id (prodcut table)

    $findproduct = & $fm->newFindCommand('products');

    $findproduct ->addFindCriterion('cid', $cid);

    $findresult = $findproduct->execute();

    $products = $findresult->getRecords();

   

    foreach($products as $product) {

        echo $product->getField('productname');

    }

}

Share this post


Link to post
Share on other sites

It appears that an error is being generated by $findresult. Trap for it with

$findresult = $findproduct->execute(); //existing code

if (FileMaker::isError($findresult)) {

	$dbmsg = '<p>Database products error (' . $findresult->code . '): ' . $findresult->getMessage() .'</p>';

	echo $dbmsg;

	exit;

}

// continue your code




This will echo something like

"Database products error (401): No records match the request."

and allow you to troubleshoot your find request.



If you add this code after each find request with the appropriate change in the message text, you can pinpoint which find request won't allow you to get records.  You can also add if statements to, for example, do something different if the found set is empty.
if (FileMaker::isError($findresult)) {

	 if($findresult->code == '401'){

		 // add code to handle no found records

	 } else {

$dbmsg = '<p>Database products error (' . $findresult->code . '): ' . $findresult->getMessage() .'</p>';

		 echo $dbmsg;

		 exit;

	 }

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Content

    • By ellpe
      Hi!

      I´m a newbie working with PHP and I wonder if anyone knows if it´s possible to use SuperContainer togehter with FmStudio Pro from FmWebSchool.

      If yes, I would be happy to learn how.

      I´m working with FmPro Server 10 Advanced in Windows Vista and FmPro Adv 11, in Win XP

      Regards LarsP, Sweden
    • By NYC Newbie
      I have an ecommerce site in which the inventory is also listed on another metasite (i.e. amazon, ebay, etc..). The metasite maintains its own separate inventory.
      I need to send a xml to the metasite's webservice whenever someone buys an item on my website.
      The purpose of this xml is to delete the item off the metasite immediately.

      I am using FMStudio for FX.php and Filemaker Pro 11.
      The delete xml will be generated upon payment confirmation from the buyer. It is autogenerated as a webpage.
      I also have a php page that sends a 'file_get_contents' to the webservice sucessfully - meaning it works just fine when sending an xml file that resides in the same folder.
      But I don't know how to integrate the two. The two files do not sit in the same folder so the latter is having a hard time finding the former, and any combination of "../foldername.php" doesn't seem to work.
      And i'm not even sure this is the most expedient way to do this so I'm open to any suggestions.

      Here is my autogenerated delete xml page in php. Basically it lists the ids of ordered items that reside in a portal on an FM layout called 'orders' -

      <?php require_once('Connections/invoices.php'); ?>
      <?php $ids_find = clone($invoices);
      $ids_find->layout = 'orders';
      $ids_findCriterions = array('orderID'=>$_REQUEST['orderid'],);
      foreach($ids_findCriterions as $key=>$value) {
      $ids_find->AddDBParam($key,$value);
      }

      fmsSetPage($ids_find,'ids',35);

      $ids_result = $ids_find->FMFind();

      if(is_a($ids_result,'FX_Error') || $ids_result['errorCode'] != "0") fmsTrapError($ids_result,"error.php");

      $ids_row = current($ids_result['data']);
      $ids_row_key = key($ids_result['data']);

      $ids_orderlineitem_portal_row = 0;
      $ids_orderpaypalvars_portal_row = 0;

      fmsSetLastPage($ids_result,'ids',35);

      fmsRedirect('Books/websitedeleteIndex.php');

      //FMStudioFX v1.0 - do not remove comment, needed for DreamWeaver support ?>
      <?php
      header('content-type: text/xml; charset=utf-8');
      echo('<?xml version="1.0" encoding="ISO-8859-1"?>');
      echo('<inventoryUpdateRequest version="1.0">');
      echo('<action name="bookupdate">');
      echo('<username>USERNAME</username>');
      echo('<password>ISSECRET</password>');
      echo('</action>');
      echo('<MetaSiteList>');
      $ids_orderlineitem_portal_rownum = 1;
      foreach($ids_row['order_line_item::bookID'] as $ids_orderlineitem_portal_row=>$ids_orderlineitem_portal){
      echo('<MetaSite>');
      echo('<transactionType>delete</transactionType>');
      echo('<vendorBookID>'.$ids_row['order_line_item::bookID'][$ids_orderlineitem_portal_row].'</vendorBookID> </MetaSite>');
      if($ids_orderlineitem_portal_rownum == 0) break; else $ids_orderlineitem_portal_rownum++;
      }//portal_end
      echo('</MetaSiteList>');
      echo('</inventoryUpdateRequest>');
      ?>

      The xml document appears in a URL formatted correctly. But I don't care for the buyers to see this page, not even a millisecond of it.

      Here is the redirected 'Books/websitedeleteIndex.php file -

      <?php require_once('post_xml.php');?>
      <?php $xml = file_get_contents('updateInventory.php');
      $url ='https://inventoryupdate.metasite.com';
      $port = 80;

      $response = xml_post($xml, $url, $port);

      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Untitled Document</title>
      </head>
      <body>
      </body>
      </html>

      I tried <?php $xml = file_get_contents('../updateInventory.php') because it sits one directory level up. Doesn't work.
      But there's got to be an easier way to send this info, yes?
      Thanks.
    • By Steven1337
      The left menu on my website is dynamic and it is based off a recordset from my filemaker database. My left menu is included on every page of my website and I do not want the find of the recordset to occur every time a user browses to a different page. I am looking for a way to store the results in a session so that it only has to look for them once per session. The code that creates my leftbar menu looks like this:



      <?php // FMStudio v1.0 - do not remove comment, needed for DreamWeaver support ?> <?php $categories_find = $Rackspace->newFindCommand('vehiclesearchsmall'); $categories_findCriterions = array('VehicleCategory'=>'=='.$_SESSION['make'],'VehicleId'=>$_SESSION['model'],'year'=>$_SESSION['year'],); foreach($categories_findCriterions as $key=>$value) { $categories_find->AddFindCriterion($key,$value); } fmsSetPage($categories_find,'categories',10000); $categories_find->addSortRule('SubCategory2',1,FILEMAKER_SORT_ASCEND); $categories_result = $categories_find->execute(); if(FileMaker::isError($categories_result)) {$error = 'yes';} else { fmsSetLastPage($categories_result,'categories',10000); $categories_row = current($categories_result->getRecords()); } ?> <?php $lis = array(); foreach ($categories_result->getRecords() as $cer) { $tac = $cer->getField('SubCategory2'); $lis[$tac] = (!isset($lis[$tac])) ? 1 : $lis[$tac] +1 ; } foreach ($lis as $nam => $valu) { echo '<dd class="categories" style="border-bottom:1px dotted #999;"><a href="cilist.php?VehicleCategory='. $_SESSION['make'] .'&SubCategory2=' . $nam . '&VehicleId=' .$_SESSION['model'] . '&year=' . $_SESSION['year'] . '" >' . $nam .'</a> '. '(' . $valu . ')' . '</dd>'; } ?>

      I tried storing the $categories_row in a session variable but it would only give me one result. I am stuck here any help would be greatly appreciated.
    • By midimid
      Something I'm a bit perplexed about. I have Filemaker 10 Advanced, FMStudio with Dreamweaver CS5 and apache installed locally. We are using fmgateway for hosting.

      Using the above, can I setup things so that I'm developing entirely locally without touching the online fmgateway DB, then move the DB and local php files online when I need to launch?
    • By Jerry100
      Does anyone know if FM Studio and Dreamweaver CS4 are compatible and if there is any advantage in purchasing CS4 instead of CS3?
×
×
  • Create New...

Important Information

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