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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.