Data feed file integration price comparison shopping script

Documentation Wiki - DataFeedFile.com - Online merchant datafeed integration for affiliates : dffPagingOffsetLimit

HomePage | Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Home Affiliate FAQ Merchant FAQ Examples Merchants Networks & Programs Forum Blog Wiki Knowledge Base Login

Revision [509]

This is an old revision of dffPagingOffsetLimit made by admin on 2008-11-30 12:14:18.
 

Implement Paging using Limit + Offset

this instruction applies to Price Search Engine (PSE), Deal Search Engine (DSE) while using XML or JSON queries.

When to use this instructions?
When you are using XML or JSON queries, you are getting data in raw format from DFF server. Sometimes the data size returned (number of search results) is too large for XML/JSON queries or does not fit on a single web page to be displayed anyways, therefore we return only a portion of the result only to save bandwidth and make the request/response faster. This is why we have the *offset* and *limit* parameter.

Why use Paging?
Any data you obtain from DFF XML/JSON query should be used to display a web page to your web site visitor, which should not be too long. For example, you should not display a web page with 200+ product results on it at one time. So, the right way to display a large data result is to show a small portion of the result at a time and allow the visitor to use paging to see the rest of the search results.

Requirements to do Paging
To use paging you must understand how to program using whatever web scripting language you have choosen (PHP, ASP, etc...). You have to understand how to get several variables such as the total results and be able to calculate basic arithmetic to determine the current page, total pages and what to set the offset + limit to. If you are not familiar enough do to this kind of programming then you probably should use XML / JSON web service queries.

How to do paging using XML?
  1. Decide how many products or rows you would like to show per page. This will be your limit value. For this example we will use 20. The default for PSE is 12.
  2. submit a request to DFF server using XML without the offset parameter, but do set the limit to 20, and set any other filtering parameter you need.
  3. Once you get the result back, first you need to check the number of results / rows returned. You should examine the parent XML tag <stats> which is located towards the end of the XML search results, which looks like this:
            <stats>
                <productlist_count>310</productlist_count>
                <core_prdt_count>310</core_prdt_count>
                <merc_prdt_count>0</merc_prdt_count>
                <productlist_total_estimate>1964</productlist_total_estimate>
           
                <price_min>0.01</price_min>
                <price_max>499.86</price_max>
            </stats>

  4. The <stats> results above tells you the summary of total records / rows returned, see below for each child tag explanation:
    • <productlist_count> tells you the total records included in this XML data result which you will find under the parent <productlist>
    • <core_prdt_count> tells you how many of the 310 products included in the data results have DFF Product SKU (price comparable using PPC).
    • <merc_prdt_count> tells you how many of the 310 products returned are not price comparable, instead it is only matched to a single merchant's product record (merchant product).
    • <productlist_total_estimate> tells you the overall total of ALL POSSIBLE result from all our servers. DFF servers do not return all search results because it is too resource intensive. For example if you search for keyword *ball* and there are 1 million results from all server, we only return around 300 - 350 results for you because the servers have found enough relevant information or too much information already, the servers will not exhaust itself searching for all matching products for the keyword *ball* this is typical for all search engines even Google and Yahoo.
    • <price_min> tells you the minimum price from the 310 products returned.
    • <price_max> tells you the maximum price from the 310 products returned.
  5. Next you need to calculate the number of total pages you will have to create the paging links by doing simple arithmetic:
                page_total = ceil(productlist_count / limit);

  6. Next you need to display a paging bar or paging navigation links on your web page.
  7. That is all !

How to do paging using JSON?
  1. Decide how many products or rows you would like to show per page. This will be your limit value. For this example we will use 20. The default for PSE is 12.
  2. submit a request to DFF server using JSON post request without the offset parameter, but do set the limit to 20, and set any other filtering parameter you need.
  3. Once you get the result back, first you need to check the number of results / rows returned. You should examine the 1st level array [stats] which is located towards the end of the JSON search results, which looks like this:
                    [stats] => stdClass Object
                        (
                            [productlist_count] => 310
                            [core_prdt_count] => 310
                            [merc_prdt_count] => 0
                            [productlist_total_estimate] => 1964
                            [price_min] => 0.01
                            [price_max] => 499.86
                        )

  4. The [stats] array results above tells you the summary of total records / rows returned, see below for each child tag explanation:
    • [productlist_count] tells you the total records included in this XML data result which you will find under the parent <productlist>
    • [core_prdt_count] tells you how many of the 310 products included in the data results have DFF Product SKU (price comparable using PPC).
    • [merc_prdt_count] tells you how many of the 310 products returned are not price comparable, instead it is only matched to a single merchant's product record (merchant product).
    • [productlist_total_estimate] tells you the overall total of ALL POSSIBLE result from all our servers. DFF servers do not return all search results because it is too resource intensive. For example if you search for keyword *ball* and there are 1 million results from all server, we only return around 300 - 350 results for you because the servers have found enough relevant information or too much information already, the servers will not exhaust itself searching for all matching products for the keyword *ball* this is typical for all search engines even Google and Yahoo.
    • [price_min] tells you the minimum price from the 310 products returned.
    • [price_max] tells you the maximum price from the 310 products returned.
  5. Next you need to calculate the number of total pages you will have to create the paging links by doing simple arithmetic:
                page_total = ceil(productlist_count / limit);

  6. Next you need to display a paging bar or paging navigation links on your web page.
  7. That is all !

Example of PHP script creating paging links using JSON array results via DFF PHP Client Library
// GET DATA USING DFF CLIENT LIBRARY
$dff_request = new DFF_Client_API;
$dff_request->set_using_DFF_config();
if($keyword!='') $pse_params['keyword'] = $keyword;
if($sort!='') $pse_params['sort'] = $sort;
if($cat1num>0) $pse_params['cat1num'] = $cat1num;
if($mernum>0) $pse_params['mernum'] = $mernum;
$pse_params['limit'] = 20;
$offset = ($page-1)*$pse_params['limit'];
$pse_params['offset'] = $offset;
$pse_params['debug'] = 1;

$result = $dff_request->post_request(DFF_PSE,$pse_params);
$dff_request->convert_json_to_array();

//WHICH RECORD IS THE FIRST AND LAST SHOWING ON CURRENT PAGE?
$rec_start = (($page-1) * $pse_params['limit'])+1;
$rec_end = ($rec_start + $pse_params['limit'])-1;
if($rec_end>$dff_request->result_array['product_count']) $rec_end = $dff_request->result_array['product_count'];

// GENERATE TOTAL PAGE
$total_page = ceil($dff_request->result_array['product_count'] / $pse_params['limit']);


Still Confused?
Doing XML/JSON query is not for a new programmer. If you have not done any paging functionality, this guide may also be somewhat confusing for you. You may want to seek for a more advanced programmer.

There are no comments on this page. [Add comment]

Integrate price comparison shopping data feed file from thousands of online merchant product data feeds | Valid CSS

Page was generated in 0.0905 seconds