dsx58940 2016-11-26 12:31
浏览 85
已采纳

使用PHP + MySQL一个web-app,其中注册的,已登录的用户可以添加一些文本,这些文本可由其他已登录的注册用户评论

I want to do using PHP+MySQL a web-app, where registered, logged user can add question or add a comment to the question (unlogged, unregistered user can only read questions and its answers).

The main problem is, how to express in PHP+MySQL the comment to the right straight question. (not to all questions in one, but directly to the right one)

Thank you for all posibilities in way of solving this problem.

  • 写回答

1条回答 默认 最新

  • doom910730 2016-11-26 14:05
    关注

    This sounds like a simple database design question.

    You are describing 3 tables: users, questions, comments. Comments table has a foreign key of QuestionID, the question in which the comment was posted. It also has a foreign key of PosterID, which is the ID of the user who posted the comment. To view the comments related to a specific question, fetch them by their QuestionID.

    Here's a sample SQL query in PHP to fetch comments for a specific question:

    $questionId = 5;
    $query = "SELECT *
    FROM comments
    WHERE question_id={$questionId}";
    $result = mysqli_query($conn, $query);
    

    I also suggest learning about SQL injection and preferably using PDO prepared statements to construct your queries (The sample I've given uses simple mysqli).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?