[FX.php List] The more you learn the less you know
Jonathan Schwartz
jonathan at eschwartz.com
Sun Aug 20 11:55:01 MDT 2006
Here I go again, trying to figure out where I am
on the FMP-CWP-fx.php-PHP continuum.
In response to my earlier request for help with
browsing a found set of records, one at a time,
Erik was kind enough to offer up this script.
Thanks Eric.
A year ago, when I was first starting out, I
would have been totally unable to make heads or
tails of the script. Today, at least I have an
idea what I am looking at and have an opportunity
to not only get the functionality I'm looking
for, but can learn along the way.
My question is this...On a scale of
Beginner/Intermediate/Advanced, how advanced is
this script? The purpose of the question is to
evaluate how much I *don't* know, compared to
what others judge to the case.
To add some granularity, here are some of the
elements I recognize, but have not learned or
implemented yet, and would like your rating on
difficulty
- setting the findProduct($search) function.
- creating an array
- defining the $head and $body variables
- single page design
- other?
Apologies for taking up bandwidth trying to
satisfy my own curiosities. Hopefully, others
will glean value from the responses.
Jonathan
----------------- Eric's Scrip Below --------------------------
<?php
session_start(); // Let's us remember stuff accross page loads
require_once ('FX/FX.php');
require_once ('inc/system.php'); // DB connection constants etc.
// Functions
// Find products by name, without 'InnerArray'
function findProducts($search)
{
global $fmshost;
global $dataport;
global $dbname;
global $user;
global $pass;
$layout = 'products';
$fx = new FX($fmshost, $dataport);
$fx->SetDBData($dbname, $layout);
$fx->SetDBUserPass($user, $pass);
$fx->AddDBParam('webtexts_productname::da', $search);
$return_data = $fx->FMFind(TRUE, 'object', FALSE);
// Transform FM data into more useful array
if (count($return_data) > 0) {
$i = 1;
foreach ($return_data AS $fmkey => $fmrecord) {
list(
$products[$i]['recid'], $test[$i]['modid'] ) =
explode( '.', $fmkey );
foreach ($fmrecord as $field => $value) {
if (isset($value)) {
$products[$i][$field] = $value;
}
}
$i++;
}
return ($products);
}
return (NULL);
}
// Add link to string
function addLink ($string, $URI = '')
{
$start = ($URI != '' ? '<a href="' . $URI . '">' : '');
$end = ($URI != '' ? '</a>' : '');
$html = $start . $string . $end;
return ($html);
}
// Show navigation widget. Links using GET
function showNavigationWidget ($count, $listRelativeURI, $current = 1)
{
$previous = '<<';
$next = '>>';
$list = 'List';
$html = addlink ($previous,
($current > 1 ? $_SERVER['PHP_SELF'] . '?id=' .
($current - 1) : '')); // Link to previous record
$html .= ' ' . addLink ($next,
($current < $count ? $_SERVER['PHP_SELF'] .
'?id=' . ($current + 1) : '')); // Add link to
next record
$html .= ' · ' . addLink
($list, $_SERVER['PHP_SELF'] . $listRelativeURI);
// Add link back to list
return ($html);
}
// The page
$head = '<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test</title>
<meta name="generator" content="BBEdit 8.2" />
</head>
';
$body = '
<body><div style="margin-left: auto; margin-right: auto; width: 500px;">
<form method="get" id="showproducts" name="showproducts">
<label for="search">Search product name: </label>
<input name="search" id="search" type="text"
size="20" value="' . $_SESSION['search'] . '"/>
<button type="submit">Search</button>
</form>
';
if (isset($_GET['search'])) // Find and/or show list of products
{
if ($_GET['search'] != $_SESSION['search']) // New search
{
$_SESSION['products'] = findProducts ($_GET['search']);
$_SESSION['foundCount'] =
count ($_SESSION['products']);
$_SESSION['search'] = $_GET['search'];
}
if ($_SESSION['products'] == NULL) // Didn't find anything
{
$body .= '<p>No matches
found for search term "' . $_SESSION['search'] .
'"<br>
Please try another search term.</p>
';
} else { // Show the list
$body .= '<table border="1">
<caption>List of ' . $_SESSION['foundCount'] . '
products matching "' . $_SESSION['search'] .
'"</caption>
';
foreach ($_SESSION['products'] AS $id => $product)
{
$body .=
'<tr><td><a href="' . $_SERVER['PHP_SELF'] .
'?id=' . $id . '">' . $product['id'] . ' ' .
$product['webtexts_productname::da'] .
(array_key_exists('webtexts_suppdata1::da',
$product) ? ', ' .
$product['webtexts_suppdata1::da'] : '') . '</a>
';
}
$body .= '</table>
';
}
}
elseif (isset($_GET['id'])) // Show
product details, with links for browsing
{
$body .= '<table border="1"
width="450px"><caption>Details for product ' .
$_GET['id'] . ' of ' . $_SESSION['foundCount'];
$body .= ' · ' .
showNavigationWidget($_SESSION['foundCount'],
'?search=' . $_SESSION['search'], $_GET['id']) .
'</caption>
<tr><th>Association<td>' .
$_SESSION['products'][$_GET['id']]['associations::name']
. '
<tr><th>Product name<td>' .
$_SESSION['products'][$_GET['id']]['webtexts_productname::da']
. (array_key_exists('webtexts_suppdata1::da',
$_SESSION['products'][$_GET['id']]) ? ', ' .
$_SESSION['products'][$_GET['id']]['webtexts_suppdata1::da']
: '') . '
<tr><th>Product price<td>' . $_SESSION['products'][$_GET['id']]['price'] . '
';
$body .= '</table>
';
}
$body .='</div>
</body>
</html>';
print $head;
print $body;
?>
---
Erik Andreas Cayré
Spangsbjerg Møllevej 169
DK-6705 Esbjerg Ø
--
Jonathan Schwartz
FileMaker 8 Certified Developer
Associate Member, FileMaker Solutions Alliance
Schwartz & Company
jonathan at eschwartz.com
http://www.eschwartz.com
http://www.exit445.com
More information about the FX.php_List
mailing list