473,408 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Not passing all records to mysql

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
2 1333
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
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

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

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
4
by: Phil Latio | last post by:
I have below a quite simple php page which queries a database table of all records and outputs the result. However on this page I only output 3 of the fields and I would like to click on a...
7
by: jj | last post by:
It's taking forever to upload 400,000 records to the database through access/odbc, and I've tried phpMyAdmin's interface but it seems to timeout during import of a CSV file. Is there a better way...
12
by: Jeff North | last post by:
I'm stumped and my brains are fried!!!! I have the following data +-------+------------------------------+------------+ | resID | FLEName | VersionNbr |...
3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
2
by: csgraham74 | last post by:
Hello, im using MS Access as a front end to link to MYSQL. although this is possibly an Access issue i thought someone would be able to help me. the error message "ODBC--insert on a linked table...
1
by: julian_m | last post by:
I'm working with mysql without referential itegrity. Let me make some small example: tableA +-----------+---------------+ | id_1 | data_1 | +-----------+---------------+ | 1 ...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
2
by: gophersounds | last post by:
When I run this simple program I am not getting any data back. The program creates a database, creates a table, populates the table with some data, and then tries to read the data. However, no...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.