[FX.php List] Record Count after the fact- Revisted

Steve Winter steve at bluecrocodile.co.nz
Tue Feb 20 16:27:57 MST 2007


Hi Jonathan,

In answer to the question in this page, if you only choose to output 20
records to the user, then yes, only the 20 you select will be sent to the
browser...

As far as how to do next/previous, here's my thoughts on it...

As you have said you're going to have to set the groupsize to 'all' to
ensure that all records are passed to PHP, next, build your array, which
does the second part of the search (and yes, you're right that was the
recommended method (and the one I'd follow) from the list to solve your
current problem)...

If you build all of those found records (the 300 of them) into an array
(with the formatted html included in the content of the array, as someone
(sorry can't remember who) suggested), then you can pass an additional
parameter along with your query which you can use to display the correct
subset of records...

Let us assume that you've put the 300 records into an array called
$finalSet, and that the array keys of that are simply default numbers (built
by doing something like (pseduo code)

foreach(foundByFMPrecord) {
  if(otherCriteriaMatch) {
    $finalSet[] = '<html codes>'.$recordValues.'</html codes>';
} }

Then if you have a parameter called $skip you can do this;

if($_REQUEST['skip']) $skip = $_REQUEST['skip']; else $skip = 0;
$lastRecord = $skip + 20;
if($lastRecord > $count($finalSet)); $lastRecord = count($finalSet);

for($i=$skip; $i<$lastRecord; $i++)
  echo $finalSet[$i];

Which will output the 20 records from $skip onwards... the fist line sets
$skip to 0 if it wasn't in the submitted parameters... the second line says
which record to go to, the third line checks to make sure that that isn't
going to be a number greater than the found set, then the foreach actually
outputs the data...

Then on the page you can have a next link something like

$nextPage = $skip+20;
if($nextPage !> count($finalSet)) {
  echo '<a href="searchPage.php?'.put the other parameters
here'.&skip='.$nextPage.'">Next</a>

Previous works in much the same way;

if($skip !=0)
  echo '<a href="searchPage.php?'.put the other parameters
here'.&skip='.$nextPage.'">Previous</a> 


Let me know how you get on... if you need more details/help, just email me
the files off list and I'll take a look for you ;-)

Cheers
Steve

-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Jonathan Schwartz
Sent: Wednesday, 21 February 2007 11:44 a.m.
To: FX.php Discussion List
Subject: Re: [FX.php List] Record Count after the fact- Revisted

Joel,

The thread was from back on Friday, where I posed the original 
question about how to accomplish a combination query.  Everyone 
agreed, I believe, that php should post-process the original found 
set.  There were two choices for what to do with the results of the 
data.  One suggestion was to create and write the resulting HTML with 
data to a variable, grab a total and then write the HTML out to the 
browser.  The other suggestion was to collect the 2nd data results in 
an array.  I went with the first approach, but now see the benefit to 
the second approach.

A couple of questions:

- Does the 300 record data array have to travel to the browser, or 
does it stay on the server.  I hope its the latter.

- The first query runs on FMP.  All subsequent PREV/NEXT links run on 
the array, right?

- What would the code look like?  There is the initial creation and 
populating of the array as the for loop progresses.   Then there are 
the "PRE/NEXT" "searches" which are more like data extractions from 
the array with given start and stop points based on groupsize.

Yikes!

J


At 2:17 PM -0800 2/20/07, Joel Shapiro wrote:
>Hiya Jonathan
>
>I had a thought from your last thread that I don't remember seeing 
>-- though maybe I just missed it...
>
>As the php goes through your FM results, can you put all your newly 
>filtered, looped-through data into a new array and then subsequently 
>only use that?  So that your $filteredResults array would contain 
>only the 300 'records' (of the 500 found by FM)?  Then it seems you 
>could do whatever you wanted to that data: display the count, 
>re-sort, prev/next, etc.
>
>maybe?
>
>-Joel
>
>
>On Feb 20, 2007, at 2:01 PM, Jonathan Schwartz wrote:
>
>>I'm baaa-aaack...with a wrinkle in the previously discussed issue 
>>of post-processing a query result to accomplish a combines AND/OR 
>>search.
>>
>>The problem now is dealing with PREV/NEXT links. I didn't realize I 
>>had a problem until this point.
>>
>>The process:
>>1) Perform part 1 of the search with FMP. Say it returns 500 
>>records. $searchResult[foundCount'] reports 500, but this is before 
>>the secondary search and can not be reported back to the user.
>>
>>2) FMP passes 500 records back to PHP and Part 2 of the search (for 
>>loop) reduces the 500 records to say, 300. I can report this back 
>>to the user, but only if I set groupsize high (500) in order to be 
>>sure to count all the records resulting from the second step.  Set 
>>it lower and the count could be wrong.
>>
>>3) I'm ready to post the first 20 records, but I have 300.  If I 
>>set groupsize to 20, I get say 15.  Can't do that. If I decide to 
>>accept the 300 records and stop the for loop at 20 records, that 
>>would be wasting alot of cycles just to to toss 90% of the data.  
>>Plus, how do I now deal with the second 20 records with PREV and NEXT
links?
>>
>>Am I thinking about this correctly?  I've already asked the end 
>>user if they *really* need checkboxes versus radio buttons on this 
>>search. ;-)
>>
>>J
>>
>>
>>--
>>
>>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
>>415-381-1852
>>
>>_______________________________________________
>>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
415-381-1852

_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.1/690 - Release Date: 16/02/2007
2:25 p.m.
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.1/690 - Release Date: 16/02/2007
2:25 p.m.
 




More information about the FX.php_List mailing list