By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Not passing all records to mysql

P: 27
Hello All,

I am trying to pass records to a mysql database, but it is only passing 1 record...

What I have so far, is it pulls selections from database, calculates weather the selection is a winner or a loser or a tie, prints out to the screen correctly, but when posting the results to the database, it only sends the first record, and not all the records even though they calculated. Hope fully someone can give me some assistance on this one...I am fairly new to this but learning tons as I go...

Here is the basics of what I am working with....

[PHP]// Get all the data from the "picksheet" table
$result3 = mysql_query("SELECT * FROM picksheet WHERE Week=$cw ORDER BY user_name")
or die(mysql_error());

echo "<table border='1'<td class='v8'>" ;

echo "<tr><th>PoolMeister</th> <th>$pass[Favorite]<br>$pass[Spread]<br>$pass[Underdog]</th>
<th>$pass[Favorite2]<br>$pass[Spread2]<br>$pass[Underdog2]</th> <th>$pass[Favorite3]<br>$pass[Spread3]<br>$pass[Underdog3]</th> <th>$pass[Favorite4]<br>$pass[Spread4]<br>$pass[Underdog4]</th> <th>$pass[Favorite5]<br>$pass[Spread5]<br>$pass[Underdog5]</th> <th>$pass[Favorite6]<br>$pass[Spread6]<br>$pass[Underdog6]</th> <th>$pass[Favorite7]<br>$pass[Spread7]<br>$pass[Underdog7]</th> <th>$pass[Favorite8]<br>$pass[Spread8]<br>$pass[Underdog8]</th> <th>$pass[Favorite9]<br>$pass[Spread9]<br>$pass[Underdog9]</th> <th>$pass[Favorite10]<br>$pass[Spread10]<br>$pass[Underdog10]</th> <th>$pass[Favorite11]<br>$pass[Spread11]<br>$pass[Underdog11]</th> <th>$pass[Favorite12]<br>$pass[Spread12]<br>$pass[Underdog12]</th> <th>$pass[Favorite13]<br>$pass[Spread13]<br>$pass[Underdog13]</th> <th>$pass[Favorite14]<br>$pass[Spread14]<br>$pass[Underdog14]</th> <th>$pass[Favorite15]<br>$pass[Spread15]<br>$pass[Underdog15]</th> <th>$pass[Favorite16]<br>$pass[Spread16]<br>$pass[Underdog16]</th><th>TB</th><th> Total Wins</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result3 )) {
// Print out the contents of each row into a table

// sample of calculations being made
if (($pass[FavScore]-$pass[Spread]) > ($pass[UndScore])) {
($Game1Winner="$pass[Favorite] -$pass[Spread]");
} elseif (($pass[FavScore] -$pass[Spread]) < ($pass[UndScore])) {
// notice that PHP uses "elseif" instead of Perl's "elsif"
($Game1Winner="$pass[Underdog] +$pass[Spread]");
} else {
($Game1Winner='Tie');
}



if (($pass[FavScore2]-$pass[Spread2]) > ($pass[UndScore2])) {
($Game2Winner="$pass[Favorite2] -$pass[Spread2]");
} elseif (($pass[FavScore2] -$pass[Spread2]) < ($pass[UndScore2])) {
// notice that PHP uses "elseif" instead of Perl's "elsif"
($Game2Winner="$pass[Underdog] +$pass[Spread2]");
} else {
($Game2Winner='Tie');
}


echo "<tr><td class='v8'>";
echo $row['user_name'];

//Sample of calculation for first game
if ($pass[FavScore]==0 and $pass[UndScore]==0)
{
echo '<TH bgcolor="white">';
}
elseif (($pass[FavScore] )==($pass[UndScore] +$pass[Spread]))
{
echo '<TH bgcolor="silver">';($Ties==$Ties++);

}
elseif (($pass[FavScore] +$pass[Spread])==$pass[UndScore])
{
echo '<TH bgcolor="silver">';($Ties==$Ties++);

}
elseif ($row['Game01']=="$Game1Winner")
{
echo '<TH bgcolor="lightgreen">';($Winner==$Winner++);
}
elseif ($row['Game01'] <>"$Game1Winner")
{
echo '<TH bgcolor="red">';($Losses==$Losses++);

}
echo $row['Game01'];
//Game 2
if ($pass[FavScore2]==0 and $pass[UndScore2]==0)
{
echo '<TH bgcolor="white">';
}
elseif (($pass[FavScore2] )==($pass[UndScore2] +$pass[Spread2]))
{
echo '<TH bgcolor="silver">';($Ties==$Ties++);
}
elseif (($pass[FavScore2] +$pass[Spread2])==$pass[UndScore2])
{
echo '<TH bgcolor="silver">';($Ties==$Ties++);
}
elseif($row['Game02']=="$Game2Winner")
{
echo '<TH bgcolor="lightgreen">';($Winner==$Winner++);

}
elseif ($row['Game02'] <>"$Game2Winner")
{
echo '<TH bgcolor="red">';($Losses==$Losses++);
}

echo $row['Game02'];


echo $row['Game16'];
echo "</td><td class='v8'>";
echo $row['Tiebreaker'];
echo "</td><td class='v8'>";
echo "$Winner";
echo "</td></tr>";

//Update/Insert total/losses/ties wins to seperate database
$con= mysql_connect("localhost","xxxxx","xxxxx");
mysql_select_db("xxxxxxxxxxxxx", $con);

$sel4="select *from Standings";

$result4=mysql_query($sel4);


$num4 = mysql_num_rows($result4);
echo "$Winner";

if ($num4 != 0)
{
$up="UPDATE Standings set W$cw='$Winner', L$cw='$Losses', T$cw='$Ties' where user_name='$row[user_name]'";
if (!mysql_query($up))
{
die('Error: ' . mysql_error());
}

}
else
{

$sql4="INSERT INTO Standings ( user_name, W$cw, L$cw, T$cw)
VALUES
('$row[user_name]','$Winner','$Losses','$Ties')";
if (!mysql_query($sql4))
{
die('Error: ' . mysql_error());
}

}
}


echo "</table>";




?>[/PHP]

Hopefully this is enough of the code for you to understand...
Thanx in advance,
Patsman77
Dec 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: 27
I now have it to the point where if no records are in the Database, it will insert them into it. If some records are in the database, it will insert new records if there are any, but..... It wont update any current values, I get an error, being....
Error: Duplicate entry 'The Swammi' for key 1 if I set user_name to primary key, and if I take away the primary key feature, then it just adds more records with the same user_name...so I get duplicate records....

here is where I am with the code....

[PHP]$sel4="select * from Standings";

$result4=mysql_query($sel4);

$num4 = mysql_num_rows($result4);

if (user_name==$row['user_name'])
{

$up="UPDATE Standings set W$cw='$Winner', L$cw='$Losses', T$cw='$Ties' where user_name='$row[user_name]'";
if (!mysql_query($up))
{
die('Error: ' . mysql_error());
}

}
else
{

$sql4="INSERT INTO Standings ( user_name, W$cw, L$cw, T$cw)
VALUES
('$row[user_name]','$Winner','$Losses','$Ties')";
if (!mysql_query($sql4))
{
die('Error: ' . mysql_error());
}
}
}



echo "</table>"; [/PHP]

Thanx,

Patsman77
Dec 13 '07 #2

P: 27
I think my problem lies in the IF statement... I think it may be in the syntax...I have tried everything..

I am trying to do (IF user_name=='$row[user_name]') where user_name is pulled from the Standings table, and '$row[user_name]' is coming from the "PICKSHEET" table in the code above....I tried changing the STANDINGS table fied to Name incase there was a conflict there to now be...(IF Name=='$row[user_name]').. by doing this I was thinking that is this is a correct statement it would update, if not it would insert... but it doesnt update, but tries to insert... this is why I think it may be a syntax error becaue these 2 values should equal each other.... Anyone enlighten me on this?

Thanx,

Patsman77
Dec 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.