Hi,
I'm trying to add in code for yahoo local results and I only want the heading to show if there are results for that term. My code is below:
<?
require("../MagicParser.php");
function Local($item)
{
print "<a href='".$item["URL"]."'>".$item["TITLE"]."</a> - ".$item["ADDRESS"].", ".$item["CITY"]." - ".$item["PHONE"]."<BR>";
}
if ($RESULT){
echo "<b>Local Results for Whatever</b>";
}
$url = "http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=myappid&query=pizza+seattle&results=3";
MagicParser_parse($url,"Local","xml|RESULTSET/RESULT/");
echo $q;
echo $q123;
?>
So instead of
if ($RESULT){
what would I use?
Thanks,
Shawn
PS..your parser is great!
Hello Shawn,
The problem here is that you only know if you have results or not once your record handler function has been called.
There are 2 ways to work around this. Firstly, you can print the heading in the record handler on the first call. Alternatively, and slightly more complicated; is to load each item into a global array, and then display the items separately afterwards.
Here's how you would modify your code for the first method:
<?php
require("../MagicParser.php");
// set a flag to indicate the first result
$first = true;
function Local($item)
{
global $first;
if ($first)
{
echo "<b>Local Results for Whatever</b>";
}
$first = false;
print "<a href='".$item["URL"]."'>".$item["TITLE"]."</a> - ".$item["ADDRESS"].", ".$item["CITY"]." - ".$item["PHONE"]."<BR>";
}
$url = "http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=myappid&query=pizza+seattle&results=3";
MagicParser_parse($url,"Local","xml|RESULTSET/RESULT/");
echo $q;
echo $q123;
?>
Remember that you can bring "Whatever" in as a global variable if you want to make this specific to the query.
Hope this helps!
Cheers,
David.