Jump to content


Photo

Help - help needed to update my table?


  • Please log in to reply
1 reply to this topic

#1 ICEcoffee

ICEcoffee
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 27 April 2006 - 01:09 PM

Hi all

I 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

            <?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());
                                    
                                }
                                
                            }
                
                    } 
            ?>

EDIT BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 April 2006 - 02:08 PM

Well, I can see one major problem right off the bat. Your WHERE clause in the SQL statement must come AFTER the SET clause.

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users