ptmuldoon Posted January 18, 2007 Share Posted January 18, 2007 Hi.First post here, and I'm pretty new to php as well, and am hoping someone can possible help with my current issue.I'm trying to add to a users table field, the number of players the user has faced in a game. So I'm trying to count the number of players in a game_xx table, and then add that number to the users table. The game table users 'player' name, and the users table users a 'login' name. Thus, I'm pretty sure I need to match the player name with the login name as well.I think I'm close but the below code is not adding it. [code=php:0]// Add total players in game to user table$sql = 'SELECT player FROM game_'.$_SESSION['game_id'];$ply_name = get_one($sql);$sql = 'SELECT login FROM users';$login = get_one($sql);$sql = 'SELECT COUNT(player) FROM game_'.$_SESSION['game_id'];$players = get_one($sql);$sql = 'SELECT total_players FROM users WHERE \''.$login.'\' = \''.$ply_name.'\' ';$total_plyr = get_one($sql);$total_player = "$total_plyr + $players"; $sql = 'UPDATE users SET total_players = '.$total_player.' WHERE \''.$login.'\' = \''.$ply_name.'\' ';$result = single_qry($sql);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/ Share on other sites More sharing options...
ptmuldoon Posted January 19, 2007 Author Share Posted January 19, 2007 Small bump.Can anyone help?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/#findComment-164421 Share on other sites More sharing options...
ptmuldoon Posted January 20, 2007 Author Share Posted January 20, 2007 Can anyone help? This is one my last items to get resolved.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/#findComment-164966 Share on other sites More sharing options...
Daniel0 Posted January 20, 2007 Share Posted January 20, 2007 I don't get your database layout and what does get_one() do? Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/#findComment-164970 Share on other sites More sharing options...
hackerkts Posted January 20, 2007 Share Posted January 20, 2007 Hmm.. You might wanna just +1 to the total players whenever a people view the page. Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/#findComment-164971 Share on other sites More sharing options...
ptmuldoon Posted January 20, 2007 Author Share Posted January 20, 2007 [quote author=Daniel0 link=topic=123050.msg509128#msg509128 date=1169297255]I don't get your database layout and what does get_one() do?[/quote]Sorry about that. get_one is just a custom function of:[code=php:0]//retrieves 1 piece of datafunction get_one($string) { $q = mysql_query($string) or die('Failed to get_one: '.mysql_error()); while ($row = mysql_fetch_array($q)) { $result = $row[0]; } return $result;}[/code]and single_query is:[code=php:0]function single_qry($string) { $result = mysql_query($string) or die('Failed to query: '.mysql_error()); return $result; }[/code]I'm still learning php, so I'm not sure I need to use type of query to get the data or not. I can abandon those custom functions too if necessary. Quote Link to comment https://forums.phpfreaks.com/topic/34797-query-two-tables-and-update-field/#findComment-164980 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.