Jump to content

issue with mysql_num_rows


gabaroar

Recommended Posts

I am having trouble calling mysql_num_rows in my script.  I get the error message "PHP Warning:  mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\scripts\update.php on line 41".  I have looked around online but can only find the my sql is not right.  I am able to copy and past the sql into mysql workbench and it runs fine.  Any help would be much appreciated.

 

$game_id = $row['id'];
            $game_name = $row['game_name'];
            
            print("updating game {$game_id}: {$game_name}" . PHP_EOL);
            
            $sql = "SELECT users.id, users.username, users.number_attended_games FROM users join game_sessions_users on game_sessions_users.user_id = users.id where game_sessions_users.game_session_id = " . $game_id;
            
            print($sql . PHP_EOL);
            
            $players = mysql_query($sql, $connection) or die(mysql_error($connection));;
            
            if(mysql_num_rows($players >= 1)){
                while($player = mysql_fetch_array($players, MYSQL_ASSOC)){
                    print('updating player: ' . $player['username']);
                    $number_attended_games = $player['number_attended_games'];
                    $user_id = $player['id'];
                    $sql = "UPDATE users SET number_attended_games = " . ($number_attended_games + 1) . ", user_level = " . ($number_attended_games / 10) . " WHERE id = " . $user_id;
                    $update_result = mysql_query($sql, $connection);
                }
            }
            
            $sql = "UPDATE game_sessions SET completed = 1 WHERE id = " . $game_id;
            $update_result = mysql_query($sql, $connection);

Link to comment
https://forums.phpfreaks.com/topic/231207-issue-with-mysql_num_rows/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.