[FX.php List] Browsing a set of found records - Resolved!

Jonathan Schwartz jonathan at eschwartz.com
Mon Aug 21 11:17:51 MDT 2006


Dale,

It's a freakin' awesome world!

I just knuckled down and forced myself to learn 
creating and manipulating arrays...and then 
easily implemented the 'next record' scheme I was 
seeking, using:
	1) Save the found set recid's to a Session array.
	2) Set the position of the current record 
in the array into a Session variable.
	3) Added a link on the Detail page, 
calling for the recid of the current record +1

Voila! Arrays are your friend. ;-)

For additional fun, I  might just add a window on 
the Detail page, showing a list of the found set 
records along with links to each.  That way, a 
user can either browse from record to record or 
jump to any other record in the original found 
set.

Let me repeat this for the benefit of beginners 
out there...spend the time learning basic PHP. 
My favorite book is "PHP for the World Wide Web" 
by Larry Ullman, Second Edition.  The 
attractiveness of this book is that it focuses on 
PHP in Web Publishing without assuming that MySQL 
in the chosen database.   Only the second to last 
chapter introduces databases, and by that time, 
you know enough PHP to discern where fx.php picks 
up.

Thanks again to the List for the support.

Jonathan






At 9:50 AM -0500 8/21/06, Dale Bengston wrote:
>It's a whole new world, but it's a really great world!
>
>On Aug 21, 2006, at 9:31 AM, Jonathan Schwartz wrote:
>
>>Yes. Thank you.
>>
>>Now on the learning about creating and manipulating arrays...
>>
>>I needed to learn this anyway. ;-)
>>
>>J
>>
>>At 9:13 AM -0500 8/21/06, Dale Bengston wrote:
>>>I will share the concept I'm using, and leave the coding to you.
>>>
>>>I'm allowing people to page through records in 
>>>"detail view" by first presenting a "list 
>>>view." As I write the list of records to the 
>>>page, I add each one's record key to a session 
>>>array. If the user clicks on a record in "list 
>>>view" to go to "detail view," I retrieve the 
>>>single record's detailed field data, and as I 
>>>write the "detail view," I find the record's 
>>>position in the session array and write 
>>>Previous and Next links to the records 
>>>adjacent to the selected record (with some 
>>>smarts for wrapping around the beginning and 
>>>end of the found set). Loading the record keys 
>>>as the list is written to the page preserves 
>>>the sort order and found count, since it was 
>>>generated by the sort/find of the last list of 
>>>records displayed.
>>>
>>>The next time you retrieve a list of records, 
>>>and/or sort them by clicking on the field 
>>>titles in the header row (I allow most of my 
>>>lists to be re-sorted this way no the fly), 
>>>the session array is re-built with the new 
>>>find/sort.
>>>
>>>Make sense?
>>>
>>>Dale
>>>
>>>On Aug 21, 2006, at 12:24 AM, Jonathan Schwartz wrote:
>>>
>>>>Care to share the scripts lines that create 
>>>>the array from the initial query and then the 
>>>>steps to pull walk the array to pull them out 
>>>>again?
>>>>
>>>>Thanks
>>>>
>>>>Jonathan
>>>>
>>>>At 12:19 AM -0500 8/21/06, Dale Bengston wrote:
>>>>>This is exactly how I do it.
>>>>>
>>>>>Dale
>>>>>
>>>>>On Aug 20, 2006, at 3:18 PM, Gjermund Gusland Thorsen wrote:
>>>>>
>>>>>>I think you should do you first search, put all the recids from the
>>>>>>selection in an array of $_SESSION and from there do a search by an
>>>>>>offset in the $_SESSION['selectionRecid']
>>>>>>
>>>>>>ggt667
>>>>>>
>>>>>>On 8/20/06, Jonathan Schwartz <jonathan at eschwartz.com> wrote:
>>>>>>>Whoa!   *That's* what I'm talking about!
>>>>>>>
>>>>>>>It's going to take me a bit to work thru this.  I
>>>>>>>did try to adapt it for use and couldn't quite
>>>>>>>make it work...yet. I am getting a blank table as
>>>>>>>a  result.  Will advise if I can't figure it out.
>>>>>>>
>>>>>>>Jonathan
>>>>>>>
>>>>>>>
>>>>>>>At 3:58 PM +0200 8/20/06, Erik Andreas Cayré wrote:
>>>>>>>>Content-Type: multipart/signed; micalg=sha1;
>>>>>>>>boundary=Apple-Mail-13--466018973;
>>>>>>>>        protocol="application/pkcs7-signature"
>>>>>>>>
>>>>>>>>
>>>>>>>>Den 20/08/2006 kl. 8.16 skrev Jonathan Schwartz:
>>>>>>>>
>>>>>>>>>This next enhancement has been on my wish list for a long time....
>>>>>>>>>
>>>>>>>>>After performing a search, I would like to
>>>>>>>>>allow users to browse the resulting records,
>>>>>>>>>one by one.  To me, this is much more efficient
>>>>>>>>>then: search/view list/display detail/return to
>>>>>>>>>list/view next.
>>>>>>>>>
>>>>>>>>>I know that this means saving the resulting set
>>>>>>>>>in an array and then walking the array.  I just
>>>>>>>>>don't know how.
>>>>>>>>>
>>>>>>>>>I imagine it must look a lot like the standard
>>>>>>>>>for each code, along with explode.  From the
>>>>>>>>>current script which lists the found set:
>>>>>>>>>
>>>>>>>>>   php foreach($searchResult['data'] as $key => $value) {
>>>>>>>>>
>>>>>>>>>               echo "<td><a href=\"detail.php?recid=";
>>>>>>>>>               $recordDetails=explode('.',$key);
>>>>>>>>>               $currentRecord=$recordDetails[0];
>>>>>>>>>               echo $currentRecord."\">".$value['myfield'][0];
>>>>>>>>>               echo "</a></td>";
>>>>>>>>>
>>>>>>>>>In addition to echoing to screen, I'm guessing
>>>>>>>>>that I need to create and populate an array.
>>>>>>>>>
>>>>>>>>>Or.....is this just a variation on PREV NEXT
>>>>>>>>>links, where the groupsize is set to 1?
>>>>>>>>>
>>>>>>>>>Anyone want to steer me in the right direction?
>>>>>>>>
>>>>>>>>I took the challenge, since I'll need a similar
>>>>>>>>feature on one of my sites soon.
>>>>>>>>
>>>>>>>>My test code is below. I hope it's readable, I
>>>>>>>>put a few comments in to help...
>>>>>>>>The code is not ready for production: check for
>>>>>>>>valid user input are missing and there may be
>>>>>>>>other stuff missing...
>>>>>>>>
>>>>>>>>All comments are welcome!
>>>>>>>>
>>>>>>>>Code:
>>>>>>>><?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 = '&lt;&lt;';
>>>>>>>>                $next = '&gt;&gt;';
>>>>>>>>                $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 .= ' &middot; ' . 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 .= ' &middot; ' .
>>>>>>>>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 Ø
>>>>>>>>
>>>>>>>>Home Tel: +45 75150512
>>>>>>>>Mobile: +45 40161183
>>>>>>>>
>>>>>>>>»If you can't explain it simply, you don't understand it well enough.«
>>>>>>>>-- Albert Einstein
>>>>>>>>
>>>>>>>>»If you don't have time to do it right, when
>>>>>>>>will you have time to do it over?«
>>>>>>>>-- John Wooden, basketball coach
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>Attachment converted: PowerBookG4 HD:smime.p7s (    /    ) (0016C0F8)
>>>>>>>>_______________________________________________
>>>>>>>>FX.php_List mailing list
>>>>>>>>FX.php_List at mail.iviking.org
>>>>>>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>>>
>>>>>>>
>>>>>>>--
>>>>>>>
>>>>>>>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
>>>>>>>
>>>>>>>_______________________________________________
>>>>>>>FX.php_List mailing list
>>>>>>>FX.php_List at mail.iviking.org
>>>>>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>>>
>>>>>>_______________________________________________
>>>>>>FX.php_List mailing list
>>>>>>FX.php_List at mail.iviking.org
>>>>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>
>>>>>_______________________________________________
>>>>>FX.php_List mailing list
>>>>>FX.php_List at mail.iviking.org
>>>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>>
>>>>--
>>>>
>>>>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
>>>>
>>>>_______________________________________________
>>>>FX.php_List mailing list
>>>>FX.php_List at mail.iviking.org
>>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>>_______________________________________________
>>>FX.php_List mailing list
>>>FX.php_List at mail.iviking.org
>>>http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>>
>>--
>>
>>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
>>
>>_______________________________________________
>>FX.php_List mailing list
>>FX.php_List at mail.iviking.org
>>http://www.iviking.org/mailman/listinfo/fx.php_list
>
>_______________________________________________
>FX.php_List mailing list
>FX.php_List at mail.iviking.org
>http://www.iviking.org/mailman/listinfo/fx.php_list


-- 

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