Echo the same thing on one page over and over again
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. :)
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!
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.
精彩评论