简体   繁体   English

我应如何使用php mysql或json文件检索数据?

[英]what should i use php mysql or json file to retrieve data?

I am developing online exam system for MCQ based Exam in php and mysql. 我正在开发基于MCQ的php和mysql在线考试系统。

My database structure is as follows : 我的数据库结构如下:

tests table -> Store data when admin create 测试表->在管理员创建时存储数据

questions table -> store questions with 5 option and ans 问题表->使用5个选项和ans存储问题

testtaken table -> store data of user give exam (inserting 1 row when user give new test) 考试表->存储用户参加考试的数据(用户进行新考试时插入1行)

ans table-> store ans given by user ans表->存储用户给定的ans

Now at user end i am currently using direct MySQL query from database and display 200 questions using jquery ui tabs. 现在在用户端,我目前正在使用来自数据库的直接MySQL查询,并使用jQuery ui选项卡显示200个问题。

From Past few weeks i analysed many things for online exam from here and there. 在过去的几周中,我从这里到那里分析了许多在线考试内容。 I come to conclusion that for questions which will be around 200 or more i will create .JSON file from database once.When users give exam every time it will not go to database and take data from JSON file. 我得出的结论是,对于大约200或更多的问题,我将一次从数据库创建.JSON文件。每次用户进行考试时,它都不会进入数据库并从JSON文件中获取数据。

So Is my desicion is good or using direct mysql quires every time ?? 那么我的决心是好还是每次都直接使用mysql进行查询? I am doing this for future because mysql will load slowly when many users give tests at a time. 我这样做是为了将来,因为当许多用户一次进行测试时,mysql将缓慢加载。

Thanks in advance 提前致谢

EDIT : - I cant use php pagination with ajax Because we have timer in exam page so user may lose time at time of loading question using pagination ( May be possible internet problem so high time waste for users ). 编辑: -我无法在ajax中使用php分页,因为我们在考试页面中有计时器,因此用户在使用分页加载问题时可能会浪费时间(可能是互联网问题,因此对用户造成了高昂的时间浪费)。

Improve yoir db design u will feel better. 改善您的数据库设计,您会感觉更好。 For example, u can just store pass fail for users, or keep just wrong answers that can be in another table with user_id. 例如,您可以只为用户存储通过失败,或仅使用user_id将错误答案保留在另一个表中。 Besides, even if you create a file its going to be unsafe. 此外,即使您创建文件,它也不安全。 So again, just compare with sending data and retrieve true/false value. 再次重申一下,只需与发送数据进行比较并获取真/假值即可。

When your data is not changing that often in the database, there would be no drawback of storing a JSON file and sending that to user every time. 当您的数据在数据库中的变化不那么频繁时,存储JSON文件并将其每次发送给用户都没有任何缺点。 Definitely it is faster. 绝对更快。

But from a design strategy it wouldn't be the best solution. 但是从设计策略来看,它并不是最佳解决方案。 What I suggest is to store the images in the file system and just store the URL in the database and query the database every time a user needs to start a exam. 我建议将图像存储在文件系统中,仅将URL存储在数据库中,并在每次用户需要进行考试时查询数据库。 In this way you have more freedom with data you will provide to the user. 这样,您将拥有更多提供给用户的数据自由度。

For example in the future if your question bank has 1000 questions and you want to select 200 of them randomly, this design would be more flexible 例如,将来如果您的问题库有1000个问题,而您想随机选择200个问题,则此设计将更加灵活

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

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