You are here:  » When there are no records to return.


When there are no records to return.

Submitted by ukdave on Wed, 2006-09-13 22:49 in

Sometimes there are no records in the data feed, for example if there was a spelling mistake in the search term or no such product. What I would like to do is print something out like "No results for search term".

How can I do that please?

p.s. magicparser rocks!

Submitted by support on Thu, 2006-09-14 09:06

Hi Dave!

Are you referring to Price Tapestry?

In this case, it does say "(no results found)" in the green header bar - for example:

http://www.webpricecheck.co.uk/search.php?q=foobar

Did you want it to display it separately in the main results area?

Cheers,
David.

Submitted by ukdave on Thu, 2006-09-14 10:29

Hi David,
I do apologise, I meant using the kelkoo feed I have been working on, the core of which is below.

<?php
header
("Content-Type: text/html;charset=utf-8");
require(
"MagicParser.php");
  
$url "http://export.kelkoo.co.uk/ctl/exportSearch?partner=tradedoubler&partnerId=96906467&nbresult=10&offset=1&siteSearchQuery=shoes&catId=100164013";
  
$numshops 0;
  
$numtotalresults 0;
  function 
myHeaderRecordHandler($record)
  {
    global 
$numshops;
    global 
$numtotalresults;
    
$numshops $record["HEADER/NUMSHOPS"];
    
$numtotalresults $record["HEADER/NUMTOTALRESULTS"];
  }
  
MagicParser_parse($url,"myHeaderRecordHandler","xml|PRODUCTSEARCH/");
  print 
"<p>Num Shops: ".$numshops."</p>";
  print 
"<p>Num Total Records: ".$numtotalresults."</p>";
  function 
myRecordHandler($item)
  {
   
//  print "<p>".$item["NUMTOTALRESULTS"]."</p>";
  
print "<p>".$item["OFFERTITLE"]."</p>";
  
//  print "<p>".$item["MERCHANTNAME"]."</p>";
  //  print "<p>".$item["MERCHANTURL"]."</p>";
  //  print "<p>".$item["PRICE"]."</p>";
  //  print "<p>".$item["COMPAREURL"]."</p>";
  //  print "<p>".$item["OFFERCATID"]."</p>";
  //  print "<p>".$item["OFFERCATNAME"]."</p>";
  //  print "<p>".$item["DELIVERYCOST"]."</p>";
  //  print "<p>".$item["MEDIUMIMAGE"]."</p>";
  //  print "<p>".$item["SMALLIMAGE"]."</p>";
  
}
  
//View the URL for testing
  
echo "$url";
  
// fetch the response and parse the results
   
MagicParser_parse($url,"myRecordHandler","xml|PRODUCTSEARCH/RESULTLIST/RESULT/");
?>

Submitted by support on Thu, 2006-09-14 11:00

Ah! In that case - all you'd need to do is set a global variable that is incremented within myRecordHandler. Then when the parsing has finished, inspect the variable, and display the "No Results" message if it is zero, for example:

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  
$url "http://export.kelkoo.co.uk/ctl/exportSearch?partner=tradedoubler&partnerId=96906467&nbresult=10&offset=1&siteSearchQuery=shoes&catId=100164013";
  
$numshops 0;
  
$numtotalresults 0;
  
$counter=0;
  function 
myHeaderRecordHandler($record)
  {
    global 
$numshops;
    global 
$numtotalresults;
    global 
$counter;
    
$counter++;
    
$numshops $record["HEADER/NUMSHOPS"];
    
$numtotalresults $record["HEADER/NUMTOTALRESULTS"];
  }
  
MagicParser_parse($url,"myHeaderRecordHandler","xml|PRODUCTSEARCH/");
  print 
"<p>Num Shops: ".$numshops."</p>";
  print 
"<p>Num Total Records: ".$numtotalresults."</p>";
  function 
myRecordHandler($item)
  {
   
//  print "<p>".$item["NUMTOTALRESULTS"]."</p>";
  
print "<p>".$item["OFFERTITLE"]."</p>";
  
//  print "<p>".$item["MERCHANTNAME"]."</p>";
  //  print "<p>".$item["MERCHANTURL"]."</p>";
  //  print "<p>".$item["PRICE"]."</p>";
  //  print "<p>".$item["COMPAREURL"]."</p>";
  //  print "<p>".$item["OFFERCATID"]."</p>";
  //  print "<p>".$item["OFFERCATNAME"]."</p>";
  //  print "<p>".$item["DELIVERYCOST"]."</p>";
  //  print "<p>".$item["MEDIUMIMAGE"]."</p>";
  //  print "<p>".$item["SMALLIMAGE"]."</p>";
  
}
  
//View the URL for testing
  
echo "$url";
  
// fetch the response and parse the results
  
MagicParser_parse($url,"myRecordHandler","xml|PRODUCTSEARCH/RESULTLIST/RESULT/");
  if (!
$counter)
  {
    print 
"<p>Sorry, no results found.</p>";
  }
?>

Cheers,
David.

Submitted by ukdave on Thu, 2006-09-14 14:42

Hi David,
thanks but it is not quite working properly. I think this is probably because you have applied the counter to the header records (myHeaderRecordHandler) rather than the to the product search results returned by the other (myRecordHandler) function.

If that is right can you help me to modify it please, I couldn't do it.
Thanks, Dave.

Submitted by support on Thu, 2006-09-14 16:09

Sorry, Dave - you're absolutely correct. It should be like this:

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  
$url "http://export.kelkoo.co.uk/ctl/exportSearch?partner=tradedoubler&partnerId=96906467&nbresult=10&offset=1&siteSearchQuery=shoes&catId=100164013";
  
$numshops 0;
  
$numtotalresults 0;
  
$counter=0;
  function 
myHeaderRecordHandler($record)
  {
    global 
$numshops;
    global 
$numtotalresults;
    
$numshops $record["HEADER/NUMSHOPS"];
    
$numtotalresults $record["HEADER/NUMTOTALRESULTS"];
  }
  
MagicParser_parse($url,"myHeaderRecordHandler","xml|PRODUCTSEARCH/");
  print 
"<p>Num Shops: ".$numshops."</p>";
  print 
"<p>Num Total Records: ".$numtotalresults."</p>";
  function 
myRecordHandler($item)
  {
    global 
$counter;
    
$counter++;
    
//  print "<p>".$item["NUMTOTALRESULTS"]."</p>";
    
print "<p>".$item["OFFERTITLE"]."</p>";
    
//  print "<p>".$item["MERCHANTNAME"]."</p>";
    //  print "<p>".$item["MERCHANTURL"]."</p>";
    //  print "<p>".$item["PRICE"]."</p>";
    //  print "<p>".$item["COMPAREURL"]."</p>";
    //  print "<p>".$item["OFFERCATID"]."</p>";
    //  print "<p>".$item["OFFERCATNAME"]."</p>";
    //  print "<p>".$item["DELIVERYCOST"]."</p>";
    //  print "<p>".$item["MEDIUMIMAGE"]."</p>";
    //  print "<p>".$item["SMALLIMAGE"]."</p>";
  
}
  
//View the URL for testing
  
echo "$url";
  
// fetch the response and parse the results
  
MagicParser_parse($url,"myRecordHandler","xml|PRODUCTSEARCH/RESULTLIST/RESULT/");
  if (!
$counter)
  {
    print 
"<p>Sorry, no results found.</p>";
  }
?>

Cheers,
David.

Submitted by ukdave on Thu, 2006-09-14 20:29

Excellent it works, thank you.