[FX.php List] Best way to sort?
Steve Winter
steve at bluecrocodile.co.nz
Fri May 18 02:44:19 MDT 2012
Hi Denis
Ummm, I'm a bit confused… you don't need to deal with the XML directly… Say your query is currently this;
$courseQuery = new FX($serverIP, $serverPort, $dataSourceType);
$courseQuery->SetDBUserPass($webUN, $webPW);
$courseQuery->SetDBData($database, $database, 'all');
$courseQuery->AddDBParam('field', 'value');
$courseData = $courseQuery->FMFind();
Then what you can do is add
$courseQuery->AddSortParam('fieldToSortBy', 'ascend');
Where the second parameter is either ascend or descend as appropriate. If you wanted to sort by two fields, then add more calls to the AddSortParam function. That way your complete call becomes;
$courseQuery = new FX($serverIP, $serverPort, $dataSourceType);
$courseQuery->SetDBUserPass($webUN, $webPW);
$courseQuery->SetDBData($database, $database, 'all');
$courseQuery->AddDBParam('field', 'value');
$courseQuery->AddSortParam('fieldToSortBy', 'ascend');
$courseQuery->AddSortParam('secondFieldToSortBy', 'ascend');
$courseData = $courseQuery->FMFind();
Now (assuming that there are results) $courseData['data'] records will be sorted by fieldToSortBy and secondFieldToSortBy.
Back to my advice, if either of those two fields are unindexable (which probably isn't really a word, but I think you get the idea ;-) because they are, for example calculations based on related fields, or some such thing, or the record set which is likely to be returned is very large, then this may well have a significant (negative) impact on performance in which case it may be better to get the data back, and then use PHP to do the sorting - that's more complex to achieve, so if this works, without noticeable performance degradation, then go with it…
Does that make sense…? does it achieve what you wanted it to…?
Cheers
Steve
> It is indeed indexed. I'm thinking of just sorting in FM - Would you happen to have a snippet to show how to sort the xml?
>
> Cheers,
> D
>
>
>
> On Thu, May 17, 2012 at 4:49 PM, Steve Winter <steve at bluecrocodile.co.nz> wrote:
> Hi Denis
>
> My thoughts...
>
> Is the field which you want to sort by indexed (or indexible) in FM...? If so, add a sort parameter to your FX query.
>
> If not, get the results back in 'whatever' order from FM and sort with PHP...
>
> That said, the only way to know for sure is to generate a large record set and try both ways...
>
> Let us know what you find...
>
> Cheers
> Steve
>
> Sent from the iPhone of Steve Winter
> Matatiro Solutions
> steve at matatirosolutions.co.uk
> +44 777 852 4776
>
> On 17 May 2012, at 21:29, Denis Somar <dsomar at gmail.com> wrote:
>
> > Any best advice on the optimal way to sort.
> >
> > I'm not doing anything wild other than sorting in descending order by creation date (and I have this field ), but wanted to know if there's an optimal way to do it. There can be between 1-(infinity and beyond) most likely 100 results sorted.
> >
> > Many thanks,
> > Denis
> > _______________________________________________
> > 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
Steve Winter
+44 777 852 4776
steve at bluecrocodile.co.nz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20120518/c8a81233/attachment-0001.html
More information about the FX.php_List
mailing list