You are here:  » Multiple Files with same page

Support Forum



Multiple Files with same page

Submitted by TWCTazz on Tue, 2005-12-13 23:10 in

What I need help with as follows:

I have id's in a database i need to use and append at the end of the url used to get the xml data.

I can get the script to pull the id and parse the info for one id, but need to be able to cycle through several id's till none are available anymore.

What would be the best way to accomplish this? Below is the meat of the php code i'm using to accomplish doing 1 id.

$sql="SELECT * FROM easo_lkey WHERE id=1";
$result=mysql_query($sql,$dbh);
$row = mysql_fetch_array($result);
$lkeyid = $row["lkey"];
$trimkey = ltrim($lkeyid);
$sql="SELECT * FROM tourney";
$result=mysql_query($sql,$dbh);
$row = mysql_fetch_array($result);
$tid = $row["ID"];
$trimid = ltrim($tid);
// Start Tourney add info
  $url = "http://easo.ea.com/easo/tiger06/tournament/get_tournament_stats.jsp?site=tw06&lkey=".$trimkey."&tournamentID=".$trimid;
       print "<p>". $url."</p>";
  $res = MagicParser_parse($url,"myRecordHandler","xml|RESULT/MEMBER/");
  mysql_connect("localhost", "XXXX", "XXXX");
  mysql_select_db("XXXXX");
  function myRecordHandler($product)
  {
// Add Tourney
     $sql2 = "
      INSERT INTO results SET
        NAME = '".mysql_real_escape_string( $product["MEMBER-NAME"] )."',
  ID = '".mysql_real_escape_string( $product["MEMBER-ID"] )."'
     ";
     print "<p>". $sql."</p>";
     print "<p>". $sql2."</p>";
    mysql_query($sql2);
  }
/* function myRecordHandler($item)
  {
    print "<h2>".$item["TOURNAMENT-COURSENAME"]."</h2>";
    print "<p>".$item["TOURNAMENT-ANTE"]."</p>";
  }
*/
  if (!$res)
  {
    print "<p>Magic Parser Error Message: ".MagicParser_getErrorMessage()."</p>";
  }

Thank you in advance for any assistance you can provide me on this.

Submitted by support on Tue, 2005-12-13 23:32

Hi,

Basically, what you need to do is make a broad SQL query (rather than restricting the result set using the WHERE clause) and then loop whilst mysql_fetch_array() continues to return rows. The construct would look something like this based on your first query (but I notice that you are making multiple queries before constructing the URL):

<?php
$sql
="SELECT * FROM easo_lkey";
$result=mysql_query($sql,$dbh);
while(
$row mysql_fetch_array($result))
{
  print 
$row["lkey"];
  print 
"<br>";
}
?>

That construct should loop through all records in your easo_table, printing the value of the lkey field in each record. Then, within the braces you would replicate the code from above calling the parse function with the URL constructed as required.

Note that your myRecordHandler function must exist outside of the loop, so you may need to refer to global variables if necessary.

I hope this is along the lines of what you were looking for... let me know how you get on!

Submitted by TWCTazz on Wed, 2005-12-14 03:46

Thank you so much, your input pointed me in the correct direction and I now have it working as it should. Thank you also for developing this usefull tool, without it I never would have been able to accomplish my utimate goal.