j4ymf Posted August 6, 2009 Share Posted August 6, 2009 hello folks i run a fantasy football website. i have this query at the moment and all ive been doing is updating the points. but now i want to update the teams and the player names. // Check the 'dreamteam' table for the Player ID $sql = "SELECT id FROM dreamteam WHERE id = '$player_id'"; $result = mysql_query($sql) or die("Error 02: Failed to check Player ID"); if ($found = mysql_fetch_assoc($result)) { // If the player exists, update the points and update flag $sql = "UPDATE dreamteam SET points = $player_points, UPDATE_FLAG = 'Y' WHERE id = '$player_id'"; //echo "<P>@@@: " . $sql; $update = mysql_query($sql) or die("Error 03: Failed to update Player $player_id"); } else { i tried this but it cant be the right way to do it // Check the 'dreamteam' table for the Player ID $sql = "SELECT id FROM dreamteam WHERE id = '$player_id'"; $result = mysql_query($sql) or die("Error 02: Failed to check Player ID"); if ($found = mysql_fetch_assoc($result)) { // If the player exists, update the points and update flag $sql = "UPDATE dreamteam SET points = $player_points, UPDATE_FLAG = 'Y' WHERE id = '$player_id'"; $sql .= "UPDATE dreamteam SET name = $player_name, UPDATE_FLAG = 'Y' WHERE id = '$player_id'"; $sql .= "UPDATE dreamteam SET team = $player_team, UPDATE_FLAG = 'Y' WHERE id = '$player_id'"; //echo "<P>@@@: " . $sql; $update = mysql_query($sql) or die("Error 03: Failed to update Player $player_id"); } else { please point me in the right direction many thanks jason Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/ Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 no thats not right at all. do $sql = "UPDATE dreamteam SET points = '$player_points', UPDATE_FLAG = 'Y', SET name = '$player_name', SET team = '$player_team' WHERE id = '$player_id'"; Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/#findComment-892408 Share on other sites More sharing options...
ldougherty Posted August 6, 2009 Share Posted August 6, 2009 You are trying to combine 3 SQL queries into one query which is not how you do it. http://dev.mysql.com/doc/refman/5.0/en/update.html You need to adjust your syntax to update table itema = valuea, itemb = valueb where condition = terms; Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/#findComment-892411 Share on other sites More sharing options...
j4ymf Posted August 6, 2009 Author Share Posted August 6, 2009 thankyou i have a read then ill be back Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/#findComment-892436 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 oops syntax error $sql = "UPDATE dreamteam SET points = '$player_points', UPDATE_FLAG = 'Y', name = '$player_name', team = '$player_team' WHERE id = '$player_id'"; Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/#findComment-892442 Share on other sites More sharing options...
j4ymf Posted August 6, 2009 Author Share Posted August 6, 2009 many thanks mikesta707 that works great, but i will have a read of idougherty post as well thanks jason Quote Link to comment https://forums.phpfreaks.com/topic/169143-solved-query-help-needed-please/#findComment-892466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.