ICEcoffee Posted April 27, 2006 Share Posted April 27, 2006 Hi allI am learning PHP slowly (all the code below is handwritten by me, cool eh?), but I can't work out why my leaderboard table is not being updated properly.I am trying to match driver names from the race results from table "t_qualy_results", with driver names in a users team tables "ff1_teams" and update previously created rows within the leaderboard table "ff1_leaderboard".I think it is the actual update statment for updating the leaderboard table that is wrong, but it may also be the logical stucture is wrong too.Please help, It's driving me nuts.Cheers[code] <?php // insert rows into Leaderboard table // echo "race variables"; mysql_select_db($database_FF1, $FF1); $raceq = ('SELECT RaceID FROM races WHERE CurrentRace = 1'); $raceresult = mysql_query($raceq) or die(mysql_error()); $row = mysql_fetch_array($raceresult); $rownum = mysql_numrows($raceresult); // $ff1q = ('SELECT TeamName, id FROM ff1_teams WHERE Active = 1') or die(mysql_error()); $ff1qresult = mysql_query($ff1q) or die(mysql_error());; while($teamrow = mysql_fetch_array( $ff1qresult )) { $leaderq = "INSERT INTO ff1_leaderboard (RaceID, TeamID, TeamName) VALUES ('$row[RaceID]', '$teamrow[id]', '$teamrow[TeamName]')"; mysql_query($leaderq) or die(mysql_error()); } // // Update Leaderboard with Qualifier results // echo "raceID = ", $row['RaceID']; // now look through qualy points $qualyq = ("SELECT * FROM t_qualy_results WHERE t_qualy_results.RaceID = '".$row['RaceID']."'") or die(mysql_error()); $qualyr = mysql_query($qualyq) or die(mysql_error()); while($qualyrow = mysql_fetch_array($qualyr)) { $ff1q = ('SELECT * FROM ff1_teams WHERE ff1_teams.Active = 1')or die(mysql_error()); $ff1r = mysql_query($ff1q) or die(mysql_error()); while($ff1row = mysql_fetch_array($ff1r)){ echo " - inner loop ", $iloop; if ($qualyrow['Driver'] == $ff1row['Driver1']){ $query = "UPDATE ff1_leaderboard WHERE ff1_leaderboard.RaceID = ".$row['RaceID']." AND ff1_leaderboard.TeamID = ". teamrow['TeamID']." SET Driver1= '$qualyrow[Driver]'" or die(mysql_error()); $result = mysql_query($query) or die(mysql_error()); } } } ?>[/code][b]EDIT BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE[/b] Quote Link to comment https://forums.phpfreaks.com/topic/8546-help-help-needed-to-update-my-table/ Share on other sites More sharing options...
ober Posted April 27, 2006 Share Posted April 27, 2006 Well, I can see one major problem right off the bat. Your WHERE clause in the SQL statement must come AFTER the SET clause. Quote Link to comment https://forums.phpfreaks.com/topic/8546-help-help-needed-to-update-my-table/#findComment-31330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.