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