You are here:  » Looping through mysql table to get values for url to parse


Looping through mysql table to get values for url to parse

Submitted by jmeier on Mon, 2008-09-08 13:34 in

I am trying to get a list of values from a mysql table to use in a url parameter to fetch xml feeds to use to update mysql data. The query should be returning the value of tourn_id which is used in the url to parse, then based on the parsed information updates the same table the tourn_id comes from, then goes on and repeats the process for the rest of the rows in the table. it does not seem to be looping through the parser as the $courseguid that gets updated in the table is the same for each $tournid value. Can someone shed some light as to what I have out of order in my code? Thanks Jim

$roundres = mysql_query("SELECT TOURN_ID from TOURNAMENT_DETAILS")or die (mysql_error());
  while ($row = mysql_fetch_array($roundres, MYSQL_ASSOC))
  {
  $tournid = $row['TOURN_ID'];
MagicParser_parse("http://easo.ea.com/easo/tiger08/tournament/get_tournament_details.jsp?site=easo&game=tiger_2008&lkey=$lkey&calltime=Sat%20Sep%206%2011:21:44%20GMT-0500%202008&sku=NA&locale=en&tournamentID=$tournid&","myRecordHandler3","xml|RESULT/");
$courseguid = $record2[0]['RESULT-COURSEGUID'];
$coursename = $record2[0]['RESULT-COURSENAME'];
$name = $record2[0]['RESULT-NAME'];
$numbers = $record2[0]['RESULT-NUMMEMBERS'];
$ownerid = $record2[0]['RESULT-OWNERID'];
$ownername = $record2[0]['RESULT-OWNERID'];
$greens = $record2[0]['ROUND-GREENS'];
$pins = $record2[0]['ROUND-PINS'];
$rough = $record2[0]['ROUND-ROUGH'];
$tees = $record2[0]['ROUND-TEES'];
$time = $record2[0]['ROUND-TIME'];
$weather = $record2[0]['ROUND-WEATHER'];
$wind = $record2[0]['ROUND-WIND'];
$updateres = mysql_query("UPDATE TOURNAMENT_DETAILS SET courseGUID = '" . $courseguid . "' WHERE TOURN_ID = '" . $tournid . "'") or die (mysql_error());
}
function myRecordHandler3($record3)
  {
  global $record2;
  $easotourn['RESULT-COURSEGUID'] = $record3['RESULT-COURSEGUID'];
  $easotourn['RESULT-COURSENAME'] = $record3['RESULT-COURSENAME'];
  $easotourn['RESULT-NAME'] = $record3['RESULT-NAME'];
  $easotourn['RESULT-NUMMEMBERS'] = $record3['RESULT-NUMMEMBERS'];
  $easotourn['RESULT-OWNERID'] = $record3['RESULT-OWNERID'];
  $easotourn['RESULT-OWNERNAME'] = $record3['RESULT-OWNERNAME'];
  $easotourn['ROUND-GREENS'] = $record3['ROUND-GREENS'];
  $easotourn['ROUND-PINS'] = $record3['ROUND-PINS'];
  $easotourn['ROUND-ROUGH'] = $record3['ROUND-ROUGH'];
  $easotourn['ROUND-TEES'] = $record3['ROUND-TEES'];
  $easotourn['ROUND-TIME'] = $record3['ROUND-TIME'];
  $easotourn['ROUND-WEATHER'] = $record3['ROUND-WEATHER'];
  $easotourn['ROUND-WIND'] = $record3['ROUND-WIND'];
  $record2[] = $easotourn;
}

Submitted by support on Mon, 2008-09-08 13:50

Hi Jim,

As you are using $record2[] within the record handler function; each itteration
of the loop is creating $record[0], $record[1], $record[2] etc. etc., however
you are only ever using $record[0], which would explain why the same values
are present every time.

Without making changes to every line that references element zero of $record2,
the easiest way to fix this would be to reset $record2 within the record
handler function, so replace:

  $record2[] = $easotourn;

...with:

  $record2 = array();
  $record2[] = $easotourn;

That should do the trick!

Cheers,
David.