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

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.