duanhe4155 2013-10-20 10:01
浏览 159
已采纳

如果存在重复数据,则替换mysql表中的数据

My page works as follows:

  • A coach logs onto an admin page of a sports team
  • He can then select his team for a forthcoming fixture
  • The team is displayed in a dropdown menu. With a different dropdown menu for each different position. Thus ensuring only players relevant to a specific position is displayed in the dropdown menu
  • Now the coach selects his team
  • He then selects the opponents against whom the selected team will play
  • He then clicks submit

When he clicks submit the isset() function is triggered which will upload the selected team to the selected_team table in my db

Ok that is easy enough and it is working. Here is my problem, lets say the coach wants to change his selection for a certain fixture. He then goes to the selection page again and redo the whole process described above. But what now happens is that the same fixture_id for opponents is uploaded to the database (only with different playernames where he changed his selection)

Example: Where Selection has been changed for a fixture enter image description here

Notice: How that the old data from 1st selection is still there and the new data from second selection just gets added to the table

What im looking for is, should the user re select a team for a certain fixture I want the new teams data to replace the old teams data. How do I go about doing this?

Please note this is a fictional database

  • 写回答

3条回答 默认 最新

  • dongshi2458 2013-10-20 10:07
    关注

    Make fixture_id a unique or primary key field and use ON DUPLICATE KEY UPDATE syntax of MySQL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大