gabaroar Posted March 20, 2011 Share Posted March 20, 2011 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 More sharing options...
annihilate Posted March 20, 2011 Share Posted March 20, 2011 This line: if(mysql_num_rows($players >= 1)){ Needs changing to: if (mysql_num_rows($players) >= 1) { Link to comment https://forums.phpfreaks.com/topic/231207-issue-with-mysql_num_rows/#findComment-1190032 Share on other sites More sharing options...
gabaroar Posted March 20, 2011 Author Share Posted March 20, 2011 Thank you. That has been driving my nuts Link to comment https://forums.phpfreaks.com/topic/231207-issue-with-mysql_num_rows/#findComment-1190038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.