dzhax Posted September 13, 2011 Share Posted September 13, 2011 I am working on a project that keeps track of someones professional record. I have a table with fields like so id name ko_wins ko_loss tko_wins tko_loss decission_wins decission_loss draws I was hoping on making an update statement that could increment the proper field + 1 when new fight data comes in Like: UPDATE fighter_stats SET ko_wins = +1 WHERE name = FIGHTERNAMEHERE; Not sure how to do it and i can not figure out how or if it is even possible. Any help is appreciated. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 13, 2011 Share Posted September 13, 2011 UPDATE fighter_stats SET ko_wins = ko_wins+1 WHERE name = FIGHTERNAMEHERE; Link to comment Share on other sites More sharing options...
dzhax Posted September 13, 2011 Author Share Posted September 13, 2011 thanks for the prompt response. Maybe it needs to be different if i am using it with php? I tried that code and it doesn't appear to work. <? include('lib/sql.dat'); $connection = mysql_connect($server,$username,$password) or die('unable to connect'); mysql_select_db($database,$connection); if (($_GET['status'] == 'Official') or ($_GET['status'] == 'NSF')){ $tko = strpos($_GET['winningMethod'],'TKO'); if($tko === true) { // TKO found in winningMethod $fightWinner = $_GET['winner']; $fName1 = $_GET['fighter1']; $fName2 = $_GET['fighter2']; $method = 'TKO'; if($fightWinner == '1'){ $sql = "UPDATE `rank_fighter_stats` SET `t_wins` = t_wins+1 WHERE `DisplayName` = '" . $fName1 . "'"; mysql_query($sql, $connection); $sql = "UPDATE `rank_fighter_stats` SET `t_losses` = t_losses+1 WHERE `DisplayName` = '" . $fName2 . "'"; mysql_query($sql, $connection); } elseif ($fightWinner == '2') { $sql = "UPDATE `rank_fighter_stats` SET `t_wins` = t_wins+1 WHERE `DisplayName` = '" . $fName2 . "'"; mysql_query($sql, $connection); $sql = "UPDATE `rank_fighter_stats` SET `t_losses` = t_losses+1 WHERE `DisplayName` = '" . $fName1 . "'"; mysql_query($sql, $connection); } else { $sql = "UPDATE `rank_fighter_stats` SET `draws` = draws+1 WHERE `DisplayName` = '" . $fName2 . "'"; mysql_query($sql, $connection); $sql = "UPDATE `rank_fighter_stats` SET `draws` = draws+1 WHERE `DisplayName` = '" . $fName1 . "'"; mysql_query($sql, $connection); } } else { // TKO NOT found in winningMethod } } mysql_close($connection);?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 14, 2011 Share Posted September 14, 2011 Make sure to check for errors with the queries. You might also want to use backquotes around the column names just to be consistent. Link to comment Share on other sites More sharing options...
JamesB Posted September 14, 2011 Share Posted September 14, 2011 also, strpos() will never return true. it will return either false or an integer. so: if($tko === true) { should be: if($tko !== false) { Link to comment Share on other sites More sharing options...
dzhax Posted September 14, 2011 Author Share Posted September 14, 2011 thanks james that was it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.