chillybeans Posted September 16, 2007 Share Posted September 16, 2007 It worked perfectly fine. It makes at a table comparing people's football predictions with the actuals scores and checks how far off the guess was, and then adds up all of the differences at the end. But I can't get it to Insert the differences into my database. The loop stops when it hits... mysql_query("INSERT INTO Week1a ($player[$scoreArray]) VALUES('$points')") //Insert Points into database or die(mysql_error()); You probably don't need to see all this code, but I'm not sure what the problem is. The query is bolded at the bottom: ------------------------------------------------------------------------------------------------ $realScore = mysql_query("SELECT * FROM Week1a WHERE name='RESULTS'") or die(mysql_error()); $guesses = mysql_query("SELECT * FROM Week1a WHERE name!='RESULTS'") or die(mysql_error()); $score = mysql_fetch_array( $realScore ); while($player = mysql_fetch_array( $guesses )){ $pointsSum = 0; echo "<td class='cellTitle'>".$player[1]."</td>"; for($i=2; $i < 34; $i +=2){ $scoreArray=33; $scoreArray ++; if ($player[$i] == $score[$i]){ // if player's team equals winning team $points = abs($score[$i+1] - $player[$i+1])-3; //Points equal absolute-value of (Actual margin of victory minus Guessed margin), minus three for the correct guess if ($player[$i] == $score[$i] && $player[$i+1] == $score[$i+1]){ // if team and margin are both correct $points -= 2; // minus another 2 point bonus from Points } echo "<td class='cellstu'><img src=\"http://example.com/".$player[$i]."-tnl.gif\"></td><td class='green'>".$points."</td>"; } if ($player[$i] != $score[$i]){ //if the player guessed the wrong team $points = $score[$i+1] + $player[$i+1]; // Points equal Actual margin plus Guessed margin echo "<td class='cellstu'><img src=\"http://example.com/".$player[$i]."-tnl.gif\"></td><td class='red'>".$points."</td>"; } mysql_query("INSERT INTO Week1a ($player[$scoreArray]) VALUES('$points')") //Insert Points into database or die(mysql_error()); $pointsSum += $points; } echo "<td class='cellTitle'>".$pointsSum."</td></tr><tr cellpadding='20px'>"; } Quote Link to comment Share on other sites More sharing options...
chillybeans Posted September 16, 2007 Author Share Posted September 16, 2007 Is it because I added that column onto the end of the database and the datafields contain zeroes and I can't write over them, or am I just using bad syntax? Quote Link to comment Share on other sites More sharing options...
ptolomea Posted September 16, 2007 Share Posted September 16, 2007 Um i think it could be that its not getting correct info now granted i have had little experience dealing with mysql but so far everything has worked what i would try is $toRun = "INSERT INTO Week1a " . $player[$scoreArray] . "VALUES " . $points; mysql_querry($toRun); Thats what has worked for me hope it works for you Quote Link to comment Share on other sites More sharing options...
chillybeans Posted September 16, 2007 Author Share Posted September 16, 2007 OK I know where the problem is now... $player[#] is returning a value in the column that I want and I only want the name of the column... I have to get the column name, however you do that. Quote Link to comment Share on other sites More sharing options...
ptolomea Posted September 16, 2007 Share Posted September 16, 2007 is your column name the name of your players? a quick google search on this came up with $result = mysql_query("SHOW COLUMNS FROM Week1a"); *modifyed from search for your example if you know some information from another field associated with that column for that player could could throw a WHERE other info = some value. dont quote my syntax on this as the site i usaly get my info from is down :/ an example would be show columns from week1a where score=1 assuming score is another column and 1 is a value in that column and is week1a a table name or is it a row name? my examples assume its a table name Quote Link to comment Share on other sites More sharing options...
chillybeans Posted September 16, 2007 Author Share Posted September 16, 2007 Week1a is the Table The players are in rows. And the Scores are in columns. I want to insert into Player 1 - Score 1, then Score 2 etc but I am getting messed up by getting the value of Player 1 Score 1 (which is null or zero) and trying to Insert the $points into that field, which to my mind sounds like it should work. Anyway, I will have to sleep on it. I bet it is a very easy fix and I will kick myself. I'm not sure how that SHOW COLUMNS works. I tried it out. maybe i'll try again tomorrow. Quote Link to comment Share on other sites More sharing options...
ptolomea Posted September 16, 2007 Share Posted September 16, 2007 that helps me alot i think you need the update statement mysql_query("UPDATE Week1a SET Score1 = " .$points " WHERE Player = '" . $player[$scoreArray] . "'"); Quote Link to comment Share on other sites More sharing options...
chillybeans Posted September 16, 2007 Author Share Posted September 16, 2007 you are correct sir. I actually just got it working, and that is what I had to do. Plus I had to make a $scoreColumn = "score".$scoreArray (1-16) and I used Where id='$id' to identify the players. Thanks for your help. Quote Link to comment 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.