pospan Posted February 4, 2016 Share Posted February 4, 2016 Hello I am working on a comment system in my custom cms i want to implement a Reply to an existing comment feature. My basic structure looks now like this. Users can only add comments with no Tree. All comments are going bellow another comment. I want only one 1 lvl after the main comment. Do I miss a field in DB, i don't get the right logic? What Am I missing in the markup? Table: komentari komentarID komentar_clanak_ID komentar_dodao komentar_email komentar_sadrzaj komentar_status komentar_datum <!--- Komentari ---> <?php if(isset($_POST['dodaj_komentar'])){ $clanak_id = $_GET['ID']; $komentar_dodao = $_POST['komentar_dodao']; $komentar_email = $_POST['komentar_email']; $komentar_sadrzaj = $_POST['komentar_sadrzaj']; if(!empty($komentar_dodao) && !empty($komentar_email) && !empty($komentar_sadrzaj)){ $upit = "INSERT INTO komentari (komentar_clanak_ID, komentar_dodao, komentar_email, komentar_sadrzaj, komentar_status, komentar_datum)"; $upit .= "VALUES ($clanak_id, '{$komentar_dodao}', '{$komentar_email}', '{$komentar_sadrzaj}', 'Na čekanju', now())"; $dodaj_komentar_upit = mysqli_query($konekcija, $upit); if(!$dodaj_komentar_upit){ mysqliGreska($dodaj_komentar_upit); } $upit = "UPDATE novost SET brojacKomentara = brojacKomentara + 1 "; $upit .= "WHERE novostID = $clanak_id "; $brojacKomentara_upit = mysqli_query($konekcija, $upit); mysqliGreska($brojacKomentara_upit); } else { echo "<script>alert('Prilikom unosa komentara ostavili ste neko od polja prazno. Molimo, ispravite to te pokušajte ponovo unijet komentar.')</script>"; } } ?> <div id="komentarOkvir"> <form class="formaIzgled" action="" method="POST" autocomplete="off"> <label for="komentar_dodao">Korisničko ime</label> <input name="komentar_dodao" type="text" placeholder="Unesite vaše ime"> <label for="komentar_email">Email</label> <input name="komentar_email" type="text" placeholder="Unesite vaš email"> <label for="komentar_sadrzaj">Sadržaj</label> <textarea name="komentar_sadrzaj" placeholder="Sadržaj komentara"></textarea> <input name="dodaj_komentar" type="submit" value="Dodaj komentar!"> </form> <?php $upit = "SELECT * FROM komentari WHERE komentar_clanak_ID = {$clanak_id} "; $upit .= "AND komentar_status = 'prihvaćen' "; $upit .= "ORDER BY komentarID DESC"; $odaberi_komentare_upit = mysqli_query($konekcija, $upit); if(!$odaberi_komentare_upit){ mysqliGreska($odaberi_komentare_upit); } while ($red = mysqli_fetch_array($odaberi_komentare_upit)){ $komentar_datum = $red['komentar_datum']; $komentar_sadrzaj = $red['komentar_sadrzaj']; $komentar_dodao = $red['komentar_dodao']; ?> <div class="komentarOdgovorOkvir"> <div class="komentarOdgovorSlika"><img src="slike/01.jpg" alt="Mountain View"></div> <div class="komentarOdgovorVrh"> <div class="pomjeriBlokDaoDatum"> <div class="komentarOdgovorDao"><?php echo $komentar_dodao; ?> </div> <div class="komentarOdgovorDatum">Dodan: <?php $komentar_datum = $komentar_datum; echo date('d.m.Y - H:i:s', strtotime($komentar_datum)); ?></div> </div> <div class="komentarGlasanje">+155</div> </div> <div class="ciscenje"></div> <div class="komentarSadrzaj"> <?php echo $komentar_sadrzaj; ?> </div> <div class="kometarOpcije"> <div class="komentarGore"> <a href="#">(15) Slažem se</a></div> <div class="komentarDole"> <a href="#">(35) Ne slažem se</a></div> <div class="komentarDrustveno"> <div class="komentarPodijeli komentarLink"> <a href="#">Podijeli</a></div> <div class="komentarPrijavi komentarLink"> <a href="#">Prijavi</a></div> <div class="komentarOdgovori komentarLink"> <a href="#">Odgovori</a></div> </div> <div class="ciscenje"></div> </div> </div> <?php } ?> <!--- MARKUP FOR COMMENT REPLY ---> <div class="odgovorNaKomentarOkvir"> <div class="odgovorNaKomentarSlika"><img src="slike/01.jpg" alt="Mountain View"></div> <div class="odgovorNaKomentarVrh"> <div class="odgovorNaKomentarPomjeriBlokDaoDatum"> <div class="odgovorNaKomentarDao">TestName</div> <div class="odgovorNaKomentarDatum">Dodan: 27.01.2016 - 00:18:56</div> </div> <div class="odgovorNaKomentarGlasanje">+5</div> </div> <div class="ciscenje"></div> <div class="odgovorNaKomentarSadrzaj"> Test content </div> <div class="odgovorNaKomentarOpcije"> <div class="odgovorNaKomentarGore"> <a href="#">(15) Slažem se</a></div> <div class="odgovorNaKomentarDole"> <a href="#">(35) Ne slažem se</a></div> <div class="odgovorNaKomentarDrustveno"> <div class="odgovorNaKomentarPodijeli odgovorNaKomentarLink"> <a href="#">Podijeli</a></div> <div class="odgovorNaKomentarPrijavi odgovorNaKomentarLink"> <a href="#">Prijavi</a></div> <div class="odgovorNaKomentarOdgovori odgovorNaKomentarLink"> <a href="#">Odgovori</a></div> </div> <div class="ciscenje"></div> </div> </div> </div> <!--- Komentari ---> How it should look like on the attached picture. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted February 4, 2016 Share Posted February 4, 2016 You should be storing comments in another table and associating it by it's article id, can also assign it's parent comment/reply id. Add whatever relative data you need, but here is a simple table structure comment_id|article_id|comment_or_reply_parent_id|comment_data|comment_timestamp|comment_owner|comment_status Query to see if article_id has any comments, from each of those results query the replies to each comment or reply to each reply. (consider all a comment and belongs under the comments parent id) You can do it all in a single JOIN query but I explained it out above. Do a layout and style however desire, but the data should exist to be able to do that and display in the order they need to be in the correct locations. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.