简体   繁体   中英

PHP Querying the database

I am in the middle of a self-project right now and I know the basics of JQUERY/PHP/SQL but I am running into problems on how to set up my website. The website functions as a quiz format where users will log in and answer questions. The questions are randomized and under the right circumstance it is okay to ask the same user a question they have already answered.

I currently have 3 tables which is users, knownQuestions, and Questions. I am looking for advice on on how to set the tables up. Even a direction towards readings that would help me in this. Everything I have found covers basic tables with small data sets. My questions are:

Is executing a query each time there is an ajax call acceptable or is there more efficient ways?

Should queries select a whole table and then use JQUERY to process the information or should I select specific results such as 'Select * from Questions where qid = "01"'?

If this is not specific enough or to generalized information, I do apologize. Any links,books, or other sources of research would be much appreciated. Thanks.

I would personally grab a page worth of questions... Maybe 10 or whatever and everything associated with the question. My tables would be users, questions, answers. I would setup a relationship between answers and ids. I would also give the questions a point value. Make sure that when you grab the data you only grab the data you are going to use. I have a status field in all my databases so I can soft delete a record. If status = 0 then it is deleted from users... But I DO NOT need to SELECT * FROM USERS to display a highscore table. I would select username, score from users where status != 0;

Any other questions?

Is executing a query each time there is an ajax call acceptable or is there more efficient ways? This highly depends on your architecture. If there is a very high amount of requirement of data to and fro from client to server then the SOCKETS are considered more efficient for that as they create a permanent pipeline for the transportation of the data, but it doesn't seem that you need a socket here, AJAX will fulfill your requirement.

For your second question:

Should queries select a whole table and then use JQUERY to process the information or should I select specific results such as 'Select * from Questions where qid = "01"'?

I would suggest that you should fetch the required data from the database server using PHP, because if you are selecting the entire table, then there would be a lot of overhead over the network to transfer that amount of data, resulting in slow loading of your website. Secondly, the database server are more efficient in filtering the result given various constraints as compared to a front-end language like javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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