Jump to content

[SOLVED] Can you look at this block of code and tell me what i did wrong?


chillybeans

Recommended Posts

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'>";

}

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

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.