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条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)