简体   繁体   English

使用 JSON 编辑 MySQL 数据库中的现有表

[英]Edit existing table in MySQL data base with JSON

There is a few JSON lines:有几条 JSON 线:

[{"id":"1","word_item":"house","word_translation":"translation1","word_language":"English","word_rank":"0"},

{"id":"26","word_item":"cat","word_translation":"translation2","word_language":"English","word_rank":"1"},

{"id":"27","word_item":"man","word_translation":"translation3","word_language":"English","word_rank":"2"},

{"id":"28","word_item":"Lorem","word_translation":"translation","word_language":"English","word_rank":"5"}]

First I get it from the server with word_rank = 0 for all the lines.首先,我从服务器获取所有行的 word_rank = 0 。 After the user types in a special input the translation of the words from "word_item", js code compares the user's answer with corresponding "word_translation".在用户输入“word_item”中单词的翻译后,js 代码将用户的答案与相应的“word_translation”进行比较。 Each error adds one point to the "word_rank", you can see it in the JSON above.每个错误都会为“word_rank”增加一个点,您可以在上面的 JSON 中看到它。

How can I update the table in my DB with php so that I could save new word ranks after the user answered the questoin?如何使用 php 更新数据库中的表,以便在用户回答问题后保存新单词排名? I mean, the user clicks the button, json changes, it is send to the server我的意思是,用户点击按钮,json 改变,它被发送到服务器

If you have the most recent version of MySQL you can filter results with JSON_CONTAINS and you can then update JSON with JSON_SET .如果您拥有最新版本的 MySQL ,则可以使用JSON_CONTAINS过滤结果,然后可以使用 JSON_SET 更新JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM