Only 1 reply displayed per post |
Only 1 reply displayed per post |
masonh928 |
Oct 7 2015, 07:48 PM
Post
#1
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
Everytime I add a comment, only the latest comment appears each new comment replaces the last coment. Point being only the latest comment is displayed, test it here!
Code Here: CODE <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/Scripts/PHP/Library.php"); Class Board{ public $Connect; public $Poster; public $PostTo; public $Post; public $PostedDate; public $Poster2; public $PostTo2; public $Post2; public $Rows; public function __construct($PostToID){ try{ $this->Connect = new pdo("mysql:host=mysql.hostinger.co.uk;dbname=u645944288_all", "u645944288_mason", "mason671"); }catch(PDOException $ex){ die(json_encode(array('outcome' => false, 'message' => 'Unable to connect'))); } $Query = $this->Connect->prepare("SELECT Username FROM Users WHERE ID = :ID"); $Query->bindValue(":ID", $PostToID); $Query->execute() or die($Query->ErrorInfo()); $Row = $Query->fetch(); $this->PostTo = $Row['Username']; } public function DisplayPosts(){ $Query = $this->Connect->prepare("SELECT * FROM Board WHERE Username = :Username ORDER BY Date DESC"); $Query->bindValue(":Username", $this->PostTo); $Query->execute() or die($Query->ErrorInfo()); $Results = $Query->fetchAll(); foreach($Results as $Rows){ $Poster = $Rows['Poster']; $Date2 = AgeDate($Rows['Date']); $Date1 = betterDate($Rows['Date']); $Class = ($Rows['Poster'] == $this->PostTo) ? "PostSelf" : "PostOther"; $Reply = $this->retrieveReplies($Rows['ID']); $Post = $Rows['Post']; echo <<<Post <br><hr><br> <section class="{$Class}"> <h3>{$Poster}</h3> <h6>{$Date1} ({$Date2})</h6> <p>{$Post} <b>({$Rows['ID']})</b></p> <p& #62;____________________________________________________________________________ __________________</p> <form method="post" action="/Action?do=Comment"> <input type="text" size="80" name="Reply"> <input type="hidden" value="{$Rows['ID']}" name="ID"><input type="submit" class="btn btn-success" value="Post Comment"> </form> <div>{$Reply}</div> </section> Post; } } private function retrieveReplies($ID){ $Query = $this->Connect->prepare("SELECT * FROM Replies WHERE IDtoReply = :ID ORDER BY Date DESC LIMIT 10"); $Query->bindValue(":ID", $ID); $Query->execute(); $Res = $Query->fetchAll(); foreach($Res as $Rows){ $Replier = $Rows['Replier']; $Date = ageDate($Rows['Date']); $Reply = $Rows['Reply']; $Reply = <<<Reply <p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> Reply; return $Reply; } } } ?> |
masonh928 |
Oct 7 2015, 10:52 PM
Post
#2
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
|
CharlesEF |
Oct 8 2015, 06:47 AM
Post
#3
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I think it is because of this section of code:
CODE foreach($Res as $Rows){ By using a return statement in the foreach loop you are returning after only 1 pass through the foreach. You could define $Reply as an array and use the implode command to show the results. Or, you could make sure $Reply is blank before entering the foreach and then just add each post to $Reply using '.=', like this:$Replier = $Rows['Replier']; $Date = ageDate($Rows['Date']); $Reply = $Rows['Reply']; $Reply = <<<Reply <p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> Reply; return $Reply; } CODE $Reply = ""; I'm not sure why you use $Replay twice but you could change the variable name. Or you could change it to:foreach($Res as $Rows){ $Replier = $Rows['Replier']; $Date = ageDate($Rows['Date']); $Reply = $Rows['Reply']; $Reply .= <<<Reply <p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> Reply; } return $Reply; CODE $Reply .= $Rows['Reply']; |
masonh928 |
Oct 8 2015, 12:05 PM
Post
#4
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
i changed var name.
|
masonh928 |
Oct 8 2015, 12:24 PM
Post
#5
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
My new code, look what happened they nested in eachother, although all thr comments were displayed
CODE <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/Scripts/PHP/Library.php"); Class Board{ public $Connect; public $Poster; public $PostTo; public $Post; public $PostedDate; public $Poster2; public $PostTo2; public $Post2; public $Rows; public function __construct($PostToID){ try{ $this->Connect = new pdo("mysql:host=mysql.hostinger.co.uk;dbname=u645944288_all", "u645944288_mason", "mason671"); }catch(PDOException $ex){ die(json_encode(array('outcome' => false, 'message' => 'Unable to connect'))); } $Query = $this->Connect->prepare("SELECT Username FROM Users WHERE ID = :ID"); $Query->bindValue(":ID", $PostToID); $Query->execute() or die($Query->ErrorInfo()); $Row = $Query->fetch(); $this->PostTo = $Row['Username']; } public function DisplayPosts(){ $Query = $this->Connect->prepare("SELECT * FROM Board WHERE Username = :Username ORDER BY Date DESC"); $Query->bindValue(":Username", $this->PostTo); $Query->execute() or die($Query->ErrorInfo()); $Results = $Query->fetchAll(); foreach($Results as $Rows){ $Poster = $Rows['Poster']; $Date2 = AgeDate($Rows['Date']); $Date1 = betterDate($Rows['Date']); $Class = ($Rows['Poster'] == $this->PostTo) ? "PostSelf" : "PostOther"; $Reply = $this->retrieveReplies($Rows['ID']); $Post = $Rows['Post']; echo <<<Post <br><hr><br> <section class="{$Class}"> <h3>{$Poster}</h3> <h6>{$Date1} ({$Date2})</h6> <p>{$Post}</p> <p& #62;____________________________________________________________________________ __________________</p> <form method="post" action="/Action?do=Comment"> <input type="text" size="80" name="Reply"> <input type="hidden" value="{$Rows['ID']}" name="ID"><input type="submit" class="btn btn-success" value="Post Comment"> </form> Post; foreach($Reply as $Rows){ $Replier = $Rows['Replier']; $Date = ageDate($Rows['Date']); $Reply = $Rows['Reply']; echo <<<Reply <p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> Reply; } } } private function retrieveReplies($ID){ $Query = $this->Connect->prepare("SELECT * FROM Replies WHERE IDtoReply = :ID ORDER BY Date DESC LIMIT 10"); $Query->bindValue(":ID", $ID); $Query->execute(); $Res = $Query->fetchAll(); return $Res; } } ?> |
masonh928 |
Oct 8 2015, 03:01 PM
Post
#6
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
ok so someone wrote this:
When the caller (variable that called it) gets it back, you check that it is an array, if nothing was returned you want false returned, then you use a loop to print the return values. do you know what he means? |
masonh928 |
Oct 8 2015, 03:02 PM
Post
#7
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
the variable that called the method? what does he mean by it?
This post has been edited by masonh928: Oct 8 2015, 03:02 PM |
CharlesEF |
Oct 8 2015, 06:38 PM
Post
#8
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
ok so someone wrote this: When the caller (variable that called it) gets it back, you check that it is an array, if nothing was returned you want false returned, then you use a loop to print the return values. do you know what he means? CODE $Reply = $this->retrieveReplies($Rows['ID']); located in the DisplayPosts() function.The current code you posted, is that the same code that produced the sample page you linked too? |
masonh928 |
Oct 8 2015, 07:09 PM
Post
#9
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
http://www.dreamincode.net/forums/forum/28-php/
This post has been edited by masonh928: Oct 8 2015, 07:17 PM |
CharlesEF |
Oct 8 2015, 08:43 PM
Post
#10
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Well, I can't read anything on that site. I keep getting script errors that will not let me proceed (in Firefox and IE).
Anyway, I think the code that is being talkied about is this: CODE $Reply = $this->retrieveReplies($Rows['ID']); The variable that calls the method is $Reply but as I said I can't read the post so this is as far as I can go.But you didn't answer my question. Is the current code you posted the same code that created the sample page you linked to? |
masonh928 |
Oct 9 2015, 12:11 PM
Post
#11
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
The code from #5 is the current code.
|
masonh928 |
Oct 9 2015, 12:12 PM
Post
#12
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
btw the thread about our topic is here. See if you can read it here:
http://www.dreamincode.net/forums/topic/38...layed-per-post/ |
CharlesEF |
Oct 9 2015, 02:22 PM
Post
#13
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I was finally able to read the other post using the Choromodo browser. Anyway, looking over your code I see you're nesting <section>'s. I think that is the reason your posts are being displayed nested. Also, I see each comment has a form, is this correct? I guess you want to allow posting comments into other comments?
I would start by inserting the closing <section> tag for each comment. Then we'll see what other problems come up. |
masonh928 |
Oct 9 2015, 02:33 PM
Post
#14
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
no each post has a comment form.
|
masonh928 |
Oct 9 2015, 02:34 PM
Post
#15
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
I don't want the sections nested, but my code is doing that.
|
masonh928 |
Oct 9 2015, 03:03 PM
Post
#16
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
It displays all the comments with it's post, but not in the desired fashion.
|
CharlesEF |
Oct 9 2015, 05:22 PM
Post
#17
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
This a sample of your display results:
CODE <section id="Board"> You do use <section> tags 3 times but I don't see any </section> closing tags. It continues like for each comment displayed until the very end, then there is 1. So, <section>'s are being nested.<h2 class="Title">Masonh928's Board of Posts</h3><br> <form action="/Action?do=Post" method="Post"> <textarea cols="100" rows="10" class="Post" name="Post"></textarea> <input type="hidden" name="Username" value="Masonh928"> <input type="file"> <br> <input type="Submit" value="Post to Board ≫" class="btn btn-success"> </form> <br><hr><br> <section class="PostSelf"> <h3>Masonh928</h3> <h6>8th Oct 2015, 1:20 AM (2 days ago)</h6> <p>Test with nl2br()<br /> implemented</p> <p& #62;____________________________________________________________________________ __________________</p> <form method="post" action="/Action?do=Comment"> <input type="text" size="80" name="Reply"> <input type="hidden" value="8" name="ID"><input type="submit" class="btn btn-success" value="Post Comment"> </form><p style="text-indent: 50px;"><a>Masonh928: </a> <b>comment 2</b><code> (1 day ago)</code></p><p style="text-indent: 50px;"><a>Masonh928: </a> <b>comment 2</b><code> (1 day ago)</code></p><p style="text-indent: 50px;"><a>Masonh928: </a> <b>comment</b><code> (1 day ago)</code></p><br><hr><br> <section class="PostSelf"> <h3>Masonh928</h3> |
masonh928 |
Oct 9 2015, 10:59 PM
Post
#18
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
Yeah, I don't know why the section tags are nested, or how my PHP code does that lol.
|
masonh928 |
Oct 9 2015, 10:59 PM
Post
#19
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
Yeah, I don't know why the section tags are nested, or how my PHP code does that lol.
|
CharlesEF |
Oct 10 2015, 12:08 AM
Post
#20
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Yeah, I don't know why the section tags are nested, or how my PHP code does that lol. Reply; CODE echo <<<Reply Change it to this:<p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> Reply; CODE echo <<<Reply <p style="text-indent: 50px;"><a>{$Replier}: </a> <b>{$Reply}</b><code> ({$Date})</code></p> </section> Reply; |
Lo-Fi Version | Time is now: 26th April 2024 - 06:50 AM |