在一页上一遍又一遍地回显相同的内容

发布于 2024-11-08 11:32:43 字数 2360 浏览 0 评论 0原文

我在一个项目上遇到了一些麻烦。为了理解这个问题,提供一些背景信息是很有用的。

所以,我正在创建一本睡眠日记。我想要创建的是以下内容。当您单击“第一天”时,您添加的评论将显示在左侧的框中。右侧的评论框供医生评论您的睡眠行为。

到目前为止,一切都很好。我从数据库中得到了这两条评论。但是当我点击第 2 天时,我应该看到第 2 天的评论。但是这不起作用。目前我只是用 jQuery 管理了第二天的点击,也许这就是问题所在。但除此之外如何解决呢?每天创建一个页面?

请不要让代码量吓跑您。 :)

在此处输入图像描述

在正确的日期保存效果很好,保存新评论后打印也效果很好。但它重复了同样的循环,导致了我猜的麻烦。

这是我的代码:

回显 phpinclude/feedbackday1.php 中的注释

<?php   
        if(mysqli_num_rows($feedbackPatient) > 0)
        {
            while($oUser = mysqli_fetch_assoc($allUsers))
            {
                echo $oUser['DiaryOpmerkingen'];
            }
        }
?>

如何获取 Feedback.php 中的日期

<div id="book1">
        <form action="" method="POST">
            <input class="confirmday" name="day" value="1"/>
            <?php include("phpinclude/feedbackday1.php"); ?>
        </form>
    </div>
    <!-- einde dag 1 -->

我的 User.class.php 中的函数

public function getFeedback($p_iUserid) {

    include("Connection.php"); //open db

    /*$dayid = mysql_real_escape_string($_GET['day']);*/    
    $id = $_SESSION['id'];

    /*DiaryId = {$dayid}*/
    try
    {
        $sql = "select DiaryOpmerkingen, DiaryDoctorcomment from tblDiary 
                WHERE fk_UserId = ".$p_iUserid."
                AND DiaryDay = '".$this->Day."';";
        $rResult = mysqli_query($link, $sql);
        return $rResult;
    }
    catch(Exception $e)
    {
        // no connection database
        $feedback = $e->getMessage();
    }
    mysqli_close($link);
}

在feedback.php - 页面的顶部

include("classes/User.class.php");

$oUser = new User();    

if(!empty($_POST['patientfb']))
{
    try
    {
        $oUser->Patientfb = $_POST['patientfb'];
        $oUser->Day = $_POST['day'];

        $oUser->saveFeedbackP($_SESSION['id']);

        $feedback = "Uw commentaar werd succesvol toegevoegd.";
    }
    catch (Exception $e)
    {
        $feedback = $e->getMessage();
    }
}

$allUsers = $oUser->getFeedback($_SESSION['id']);

完全卡在这里。我真的希望有人能帮助我。希望问题清楚。如果您需要更多代码,请询问。提前致谢!

I'm having some trouble with a project. To understand the problem it's useful to give a little backgroundinfo.

So, I'm creating a sleepingdiary. What I want to create is the following. When you click on day 1, the comment you added appears in the box on the left. The commentbox on the right is for the doctor who comments on your sleeping behaviour.

So far, so good. I get both comments from the database. But when I click on day 2, I should see the comments from day 2. However this doesn't work. Currently I just managed the click on day 2 with jQuery, maybe that's the problem. But how to fix it otherwise? Create a page for every day?

Please don't let the amount of code scare you away. :)

enter image description here

Saving on the right day works fine, printing after saving a new comment works fine as well. But it's echoing the same loop that causes the trouble I guess.

Here's my code:

echo the comment in phpinclude/feedbackday1.php

<?php   
        if(mysqli_num_rows($feedbackPatient) > 0)
        {
            while($oUser = mysqli_fetch_assoc($allUsers))
            {
                echo $oUser['DiaryOpmerkingen'];
            }
        }
?>

how I get the days in feedback.php

<div id="book1">
        <form action="" method="POST">
            <input class="confirmday" name="day" value="1"/>
            <?php include("phpinclude/feedbackday1.php"); ?>
        </form>
    </div>
    <!-- einde dag 1 -->

The function in my User.class.php

public function getFeedback($p_iUserid) {

    include("Connection.php"); //open db

    /*$dayid = mysql_real_escape_string($_GET['day']);*/    
    $id = $_SESSION['id'];

    /*DiaryId = {$dayid}*/
    try
    {
        $sql = "select DiaryOpmerkingen, DiaryDoctorcomment from tblDiary 
                WHERE fk_UserId = ".$p_iUserid."
                AND DiaryDay = '".$this->Day."';";
        $rResult = mysqli_query($link, $sql);
        return $rResult;
    }
    catch(Exception $e)
    {
        // no connection database
        $feedback = $e->getMessage();
    }
    mysqli_close($link);
}

On the top of the feedback.php - page

include("classes/User.class.php");

$oUser = new User();    

if(!empty($_POST['patientfb']))
{
    try
    {
        $oUser->Patientfb = $_POST['patientfb'];
        $oUser->Day = $_POST['day'];

        $oUser->saveFeedbackP($_SESSION['id']);

        $feedback = "Uw commentaar werd succesvol toegevoegd.";
    }
    catch (Exception $e)
    {
        $feedback = $e->getMessage();
    }
}

$allUsers = $oUser->getFeedback($_SESSION['id']);

Totally stuck here. I really hope someone can help me out. Hope the question is clear. If you need more code, just ask. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-11-15 11:32:43

我不确定我是否理解您的目标到底是什么。

也许你可以尝试使用数组?以这样的方式对其进行排序,最后两个注释始终位于数组的开头或末尾。根据用户点击的日期,您可以仅显示两条最新或第一条评论。

I am not sure if i understand what your goal exactly is.

Maybe you could try to use an array? Sort it in such a way, that the last two comments always are in the beginning or the end of the array. And depending on the day the user clicks on, you could display only the two latest or first comments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文