You are here:  » Setting a Table Width

Support Forum



Setting a Table Width

Submitted by KPocock on Fri, 2008-04-04 19:31 in

Thank you so much for your help this evening, Magic Parser is great !
You kindly gave me this code,

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
  }
  print 
"<h1>BBC News Headlines</h1>";
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  print 
"<table>";
  print 
"<tr>";
  print 
"<td>";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  print 
"</td>";
  print 
"</tr>";
  print 
"</table>";
?>

My first question is how do you control the table width ? I would like it to be about 650 wide..
Also is it possible to control the number of post that get included.

I Have looked through the forums, but cant see the answer.

Yes Yes, I know probably very simple, but not to me !!

Once again many thanks.
Keith.

Submitted by support on Fri, 2008-04-04 19:37

Hello Keith,

Thank you for your comments.

Both are relatively easy to do. The table width is just a case of adding a width='650' (or as required) to the TABLE tag.

Limiting the number of records displayed can be done by utilising the fact that Magic Parser will stop reading records if myRecordHandler returns TRUE, so what you need to do is setup a global counter variable, increment this variable during each itteration; and then return TRUE when it reaches the maximum number of records you want to display.

Combining both of these into the example posted earlier, have a go with something like this:

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  
// counter variable to limit number of records displayed
  
$counter 0;
  function 
myRecordHandler($item)
  {
    
// bring in $counter from the global variable scope
    
global $counter;
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
// increment $counter:
    
$counter $counter 1;
    
// see if we have reached the number of records we want, for example 3
    // and return TRUE which will stop Magic Parser if this is the case...
    
if ($counter == 3)
    {
      return 
TRUE;
    }
  }
  print 
"<h1>BBC News Headlines</h1>";
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
// alternation below to make the table 650 pixels width
  
print "<table width='650'>";
  print 
"<tr>";
  print 
"<td>";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  print 
"</td>";
  print 
"</tr>";
  print 
"</table>";
?>

(see comments inline for more guidance)

Hope this helps!
Cheers,
David.

Submitted by KPocock on Fri, 2008-04-04 19:50

David you truly are a star, your product is excellent and you customer service outstanding, as you know I know sod all about programming, so your help has been amazing, in just a few minutes I have been able to do what I have been trying for about 10 days !

I know nothing about web design etc, but do know about marketing, this product is excellent, so many people would love to use it.

Many thanks, I can now sleep tonight !

Kindest Regards,
Keith.