DavidAM Posted August 8, 2012 Share Posted August 8, 2012 As one other contributor noted the table name should be in backticks (or none at all). However, the query is fine. The query I provided doesn't need a WHERE clause and using one would actually make it fail to produce the correct results. I actually tested this logic on a table so I know it works. Let me explain how it works because it is not completely obvious how it works but is actually pretty ingenious in my humble opinion. I have to agree, that is an elegant solution. Sorry, I did not get it at first. It is just the kind of solution I look for to avoid IF's and CASE's and looping queries. @mbb87 The reason it is updating rows you don't want it to is because you are not limiting the update to the specific team you are dealing with. Since we haven't actually seen the query that selects the list of players, we can't offer a complete solution. However, some kind of WHERE clause selecting the team in question should work. If the database is normalized, it would require a JOIN to the table that links players to their team. You would have to pass the team ID in a session field (preferred) or a hidden form field (not recommended) between the two scripts. Sorry, I missed the quotes (instead of backticks) on the table name and sent you down the wrong road. For the record, I never use backticks on table or column names. If I accidentally use a reserved word for a (table or column) name, I change the name. While using backticks is permitted (not required); it makes the code more difficult to read (IMO) and leads to problems if you forget them or inadvertently use single-quotes. I just eliminate the potential problems by not using reserved words for names and therefore not needing to use backticks. Quote Link to comment 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.