You are here:  » forming a condition on feed function


forming a condition on feed function

Submitted by keyesque2 on Fri, 2010-12-31 02:42 in

Before I start, at the expense of overstaying my welcome, I have tried ways of making a condition statement based on whether the feed shows results - understanding that $record values are always present. No matter if they bring values.

Too, there is the problem of the print placement - it has to appear above the function (though below it as well, for a second ocurance, but this shouldn't pose as much a problem). While the page handles other passed variables.

Is there anything analogous to ($_SERVER['QUERY_STRING']=='' ) that could be placed overabove, for detecting the returned $url request?

With the basic makeup as:

require("MagicParser.php");
  $url = "http://feedsite.com...
  function myRecordHandler($record)
  {
print "<a href='".$record["LINK"]." target='_blank' class="CH">".$record["TITLE"]."</a>";
  }
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

Submitted by support on Fri, 2010-12-31 10:54

Hi,

A simple way to show a message if there are no results is to use a counter, and then test the counter after the parse, for example:

  require("MagicParser.php");
  $url = "http://feedsite.com...
  $counter = 0;
  function myRecordHandler($record)
  {
    global $counter;
    $counter++;
    print "<a href='".$record["LINK"]." target='_blank' class="CH">".$record["TITLE"]."</a>";
  }
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  if (!$counter)
  {
    print "<p>There are no items to display.</p>";
  }

Apologies if i've not fully understood your question, but hope this helps!

Cheers,
David.

Submitted by keyesque2 on Fri, 2010-12-31 12:16

David,

This has to appear high on the page, above all results, from a conditional echo. Doing a PRINT from within brackets wants to place the result in the same manner as the results, only listing it uppermost among $record results. I need to go higher, out of all $results.

What I must echo has its own separate div tag that preceeds all output.

I can try such a counter to return a variable to check against, but given this is php I don't think anything can go higher on the page in the way I need.

How about a check on the xml within the $url? Though I'm not sure how this would be coded. Checking the raw xml file within php.

Submitted by support on Fri, 2010-12-31 12:22

Hi,

What about creating your HTML into a variable within myRecordHandler, and then after the parse if there are results print your header followed by the HTML? For example:

  require("MagicParser.php");
  $url = "http://feedsite.com...
  $counter = 0;
  $html = "";
  function myRecordHandler($record)
  {
    global $counter;
    $counter++;
    global $html;
    $html .= "<a href='".$record["LINK"]." target='_blank' class="CH">".$record["TITLE"]."</a>";
  }
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  if ($counter)
  {
    print "<div>Your custom header here</div>";
    print $html;
  }
  else
  {
    print "<div>There are no items to display.</div>";
  }

Note how the code above uses the .= operator to append the HTML to the $html variable and build it up over all records...

Hope this helps!
Cheers,
David.

Submitted by keyesque2 on Fri, 2010-12-31 12:58

That makes the header appear at the end of (while among) all results, shrinking the width from what it needs to be (same with as results). This displaces all links altogether in their own continuous string (the record LINK hyperlinks) below this header.

Submitted by support on Fri, 2010-12-31 13:05

Hi,

Could you perhaps create an example of how you want the output to appear, e.g.

Header
Record
Record
Record
Footer

etc.?

Thanks,
David.

Submitted by keyesque2 on Fri, 2010-12-31 13:08

Please hold on, I'm trying with a variation of css.

Submitted by keyesque2 on Fri, 2010-12-31 13:42

Okay, cannot seem to pull off with css.

Wanting to appear as:

Results by "companyX" //in a div, ideally with vertical borders aligning with below

All Magic Parser - record links, descriptions

At the tailed end of all results, there is a button which is now being PRINT'ed successfully.(returning vistors to top of page). This does use the $counter

Submitted by support on Fri, 2010-12-31 14:40

Hi,

Don't forget you can create output anywhere in the script you like - and just include the call to MagicParser_parse() at the appropriate place, e.g.

  require("MagicParser.php");
  $url = "http://feedsite.com...
  $counter = 0;
  $html = "";
  function myRecordHandler($record)
  {
    global $counter;
    $counter++;
    print "<a href='".$record["LINK"]." target='_blank' class="CH">".$record["TITLE"]."</a>";
  }
  print "<h1>Results by Company X</h1>";
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

This will print "Results by Company X" followed by all the links. The position of the myRecordHandler function in the script doesn't matter at all, the output will appear wherever your call to MagicParser_parse() is...

Hope this helps,
Cheers,
David.

Submitted by keyesque2 on Fri, 2010-12-31 14:56

But that still doesn't give the "Results by Company" only when there are actual results. It shows all the time.

And when the - if ($counter) - is applied before the MagicParser_parse()
it does not show at all.

Submitted by support on Fri, 2010-12-31 15:00

Hi,

Another thing you can do is print the heading the first time myRecordHandler is called - try something like this:

  require("MagicParser.php");
  $url = "http://feedsite.com...
  $counter = 0;
  $html = "";
  function myRecordHandler($record)
  {
    global $counter;
    $counter++;
    if ($counter == 1)
    {
      print "<h1>Results by Company X</h1>";
    }
    print "<a href='".$record["LINK"]." target='_blank' class="CH">".$record["TITLE"]."</a>";
  }
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

Hope this helps!
Cheers,
David.

Submitted by keyesque2 on Fri, 2010-12-31 16:31

You bet it helps. Muchas gracias.