473,788 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not passing all records to mysql

27 New Member
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("SE LECT * FROM picksheet WHERE Week=$cw ORDER BY user_name")
or die(mysql_error ());

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

echo "<tr><th>PoolMe ister</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_arr ay( $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==$Ti es++);

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

}
elseif ($row['Game01']=="$Game1Winner ")
{
echo '<TH bgcolor="lightg reen">';($Winne r==$Winner++);
}
elseif ($row['Game01'] <>"$Game1Winner ")
{
echo '<TH bgcolor="red">' ;($Losses==$Los ses++);

}
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==$Ti es++);
}
elseif (($pass[FavScore2] +$pass[Spread2])==$pass[UndScore2])
{
echo '<TH bgcolor="silver ">';($Ties==$Ti es++);
}
elseif($row['Game02']=="$Game2Winner ")
{
echo '<TH bgcolor="lightg reen">';($Winne r==$Winner++);

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

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","xxx xx","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','$L osses','$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 1360
patsman77
27 New Member
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==$ro w['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','$L osses','$Ties') ";
if (!mysql_query($ sql4))
{
die('Error: ' . mysql_error());
}
}
}



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

Thanx,

Patsman77
Dec 13 '07 #2
patsman77
27 New Member
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=='$ro w[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
3848
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 could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
4
1369
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 particular row which would then bring up a detail page (which displays all the fields (perhaps 10 or more) of that record). Do I create another php file called detail.php which includes the line: $sql = 'SELECT * FROM `link` WHERE link_id = $id; and...
7
9297
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 to import 400,000+ records?
12
1883
by: Jeff North | last post by:
I'm stumped and my brains are fried!!!! I have the following data +-------+------------------------------+------------+ | resID | FLEName | VersionNbr | +-------+------------------------------+------------+ | 1 | 35_laserdatandria2104.zip | 1.0 | | 2 | 35_laserdatandria2104.zip | 1.23 | | 3 | 35_microweb1.31.zip | 1.0 | | 4 | 35_microweb1.31.zip | 1.234 |
3
2673
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 to print the selected records of the selected month > Can any one advise on the below Below is code i am trying to adapt (Thanks Don) 1.This first part is causing me problems so i have deleted it as it strikes me that it is looking for a...
2
2423
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 'tablname' failed" is displayed when i attempt to insert records to the MYSQL table. Does anyone know of a way round this ?? im using the most recent MYSQL driver and i have only text fields in my insert statement.
1
3528
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 | bla1 | | 2 | bla2 | | 3 | bla3 |
11
3826
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 = mysql_query("select * from $tableInfo") ; for ($i = 0; $i < mysql_num_rows($result); $i++) {
2
2182
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 records are returned in the ResultSet. I verify through MySQL Query Browser that the database is created and populated. I've also been unable to retrieve records with other databases. Because I'm creating the database at the root I don't think admin...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.