更新分数以覆盖以前的分数
我有一个页面,列出了诗歌标题、平均分数,并列出了对诗歌进行评分的评委。这些项目分为 3 列。当评委点击诗歌标题时,他会进入诗歌概览页面,该页面显示诗歌内容,并允许评委对这首诗进行从 1 到 3 的评分。如果评委已经对这首诗打分,则他的分数会加载到诗歌中下拉列表中会出现一条消息,表明他已经得分,如果他更改分数,则会更新他的分数。我的更新查询不起作用,但我想知道这是否是由于我的逻辑问题造成的。
有问题的完整代码在这里。更新查询从第 86 行开始。我的想法是是否已经有分数,arrDuplicate 数组将显示一条消息,说明并加载下拉列表中的上一个分数。如果需要,裁判可以更改分数。然而,按照现在的情况,分数每次都会写入新记录,而不是更新现有分数。
PoemScores表由poemID、judgeID和score组成。没有pk。应该有吗?
I have a page that lists poem titles, average scores and lists the judges who have scored the poems. These items are in 3 columns. When the judge clicks on the poem title, he is taken to the poem overview page that displays the poem content and allows the judge to rate the poem from 1 to 3. If the judge has already scored the poem, his score is loaded in the drop down list and a message appears saying he has already scored it and if he changes the score, it will update his score. My update query is not working but I wonder if it is due to a logic issue on my behalf.
The full code in question is here. The update query starts on line 86. My thinking is if there is a score already, the arrDuplicate array will display a message saying saying and load the previous score in the drop down list. The judge may change the score if desired. However, the way things are now, the score is being written to a new record each time and not updating the existing score.
The PoemScores table consists of poemID, judgeID, and score. There is no pk. Should there be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要添加
到您的查询中,否则它将尝试更新该特定诗歌的每个分数。
You will need to add
to your query, otherwise it will try to update every score for that particular poem.
将cfqueryparam添加到duplicateCheck、updateScore和qRatePoem查询中,主要是为了避免SQL注入。
您可以将其
(字符串比较)更改为此(数字比较)
,甚至只是此(布尔值)。
这两个 IF 语句是相同的,因此如果没有错误,您将同时执行更新和插入。你需要重新思考你的逻辑。
您可能想在此处添加额外的 IF 语句,检查 arrDuplicates 是否也有长度。如果是,则他们之前已对此进行评分,请执行更新查询。否则进行插入。
Add cfqueryparam to the duplicateCheck, updateScore and qRatePoem queries, primarily to avoid SQL injection.
You can change this
(which is a string comparison) to this (numeric comparison)
or even just this (boolean)
These 2 IF statements are identical, so if there are no errors, you will do both an Update then an Insert. You need to rethink your logic.
You probably want to add an extra IF statement here checking if arrDuplicates also has length. If it does, they've previously scored this, do the update query. Otherwise do the insert.