You are here:  » Trying to create an array


Trying to create an array

Submitted by mrw2020 on Fri, 2009-05-22 09:23 in

Hi Everyone

I really would like some help in setting up an array that will be accessed by a drop down menu. I have the basic code for getting the the xml feed and printing it out (see below) I have adapted and used the scripts from this site - many thanks.

Any ideas?

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<h3>".$item["TITLE"]."</h3.>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
  }
  print 
"<h1>Daily Horoscope</h1>";
  
$url "{link saved}";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Submitted by support on Fri, 2009-05-22 15:58

Hi There,

Essentially this is just a case of creating the HTML for the drop-down menu (I assume that you mean a select box on an HTML form) within the myRecordHandler() function, having started the form before calling MagicParser_parse(), and completing the form HTML after the call.

However, the exact implementation would depend on what option values and text you wanted in the drop down box, so if you could give more details I could help you out further with this; but to demonstrate what I mean, here is how you could create a drop-down box as part of a form during the parse...

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<option value='".htmlentities($item["TITLE"])."'>".$item["TITLE"]."</option>";
  }
  print 
"<h1>Daily Horoscope</h1>";
  
$url "{link saved}";
  print 
"<form>";
  print 
"<select name='mySelectBox'>";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  print 
"</select>";
  print 
"</form>";
?>

Hope this helps!
Cheers,
David.

Submitted by mrw2020 on Fri, 2009-05-22 16:05

Hi David

Thank you for answering so quickly, what I need in the drop down box is the 'TITLE'/zodiac sign, so that people select their star sign and then a paragraph with the daily forecast underneath, so that only the title value is in the option but the description needs to be displayed underneath in a blockquote/paragraph. I hope this makes sense and that it's actually possible

Thank you again for your support

Madeleine

Submitted by mrw2020 on Fri, 2009-05-22 17:31

Hi David

I don't know if you received my reply, but thank you very much for the code, it displays the signs very well. I need now to display the daily description/horoscope in either a paragraph or as a blockquote underneath the select box, I have sneaky suspicion that I will have to come up with some sort of array to associate the description with the correct sign - any thoughts?

and thank you again for your support.

Madeleine

Submitted by support on Fri, 2009-05-22 18:23

Hello Madeleine,

This should be relatively straight forward actually. All you need to do is use the FORM to send the sign name you want through to the page (so using the GET method), and then during the loop where the drop-down is being generated; if the current sign matches the sign you want to display, copy the reading (DESCRIPTION I assume) into a global variable; and then display it after the parse. Have a go with something like this...

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($item)
  {
    global 
$description;
    print 
"<option value='".htmlentities($item["TITLE"])."'>".$item["TITLE"]."</option>";
    if (
$_GET["sign"]==$item["TITLE"])
    {
      
$description $item["DESCRIPTION"];
    }
  }
  print 
"<h1>Daily Horoscope</h1>";
  
$url "{link saved}";
  print 
"<form method='GET'>";
  print 
"<select name='sign'>";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  print 
"</select>";
  print 
"<input type='submit' value='Go' />";
  print 
"</form>";
  if (
$_GET["sign"])
  {
    print 
"<p>".$description."</p>";
  }
?>

Hope this helps!
Cheers,
David.

Submitted by mrw2020 on Fri, 2009-05-22 19:31

Hat's off to you David it works a treat, can I just say that I think this is one of the most supportive and constructive forums I have been associated with - plus the fact 'magic parser' is pretty cool too; in fact the only problem is my lack of php savvy! hopefully I can improve but you know what they say 'you can't teach an old dog new tricks' ;)

Best Wishes
Madeleine

Old Wisdom...
'A balanced diet is a biscuit in both hands'