Rating System in PHP and MySQL

前端 未结 3 1598
花落未央
花落未央 2021-01-21 15:00

If we look at the stackoverflow website we have votes. But the question is what is the bestway to store who has voted and who has not. Lets also simplify this even more and say

3条回答
  •  旧巷少年郎
    2021-01-21 15:16

    I believe your design won't be able to scale for large numbers of voters. The typical thing to do is to create to tables

    Table 1: question - Id(INT) | userId(INT) | title(TEXT)
    Table 2: question - ID(INT) | vote(INT) | ratedBy(TEXT)

    Then you can count the votes with a query like this:

    SELECT t1.question_Id, t1.userId, t1.title, t2.sum(vote)
    FROM table1 t1
    LEFT JOIN table2 t2 ON t1.question_id = t2.question_id
    

提交回复
热议问题