PineSmokes Posted October 25, 2015 Share Posted October 25, 2015 Trying to style the comments section here but it's a little challenging to style the response from a database. I would like for starters a simple HR tag on the top but when I do that it duplicates with the one on the bottom. This is the live page: http://www.golden-wand.com/comments/index.php This is the PHP code from the section I need help styling: <?php include '../Scripts/connection.php'; $sql = "SELECT id, name, email, subject, comment FROM comment"; $result = $connect->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo " <table class='commenttable'> <tr> <td class='id'> <u>Loyal Client ". $row["id"] . "</u>: </td> <td class='subject'> " . $row["subject"]. " </td> </tr> <tr> <td></td> <td class='comment' colspan='2'> " . $row["comment"]. " </td> </tr> </table> <hr class='commenthr'>"; } } else { echo "No Comments"; } ?> I've also uploaded the index.php page just in case I've edited the live version, thanks for any help index.php index.php Quote Link to comment https://forums.phpfreaks.com/topic/298809-styling-comment-section-from-database/ Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 (edited) Do not post duplicate posts for the same thing Edited October 25, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298809-styling-comment-section-from-database/#findComment-1524248 Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 (edited) Your first problem is you need to take the table start and end tags out of the while loop. If you have the <hr> in the loop it is going to keep repeating. Your better off putting the DB variables in parenthesis instead of doing all that escaping. {$row["subject"]} Edited October 25, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298809-styling-comment-section-from-database/#findComment-1524249 Share on other sites More sharing options...
Solution printf Posted October 26, 2015 Solution Share Posted October 26, 2015 This looks like a PHP question, not a SQL question! Anyway, move the <table> out of the loop, and then just style your <tr> tag with a border-top or border-bottom. <td> <table class='commenttable'> <?php include '../Scripts/connection.php'; $sql = "SELECT id, name, email, subject, comment FROM comment"; $result = $connect->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo " <tr style=\"border-bottom: 1px solid #000;\"> <td class='id'> <u>Loyal Client ". $row["id"] . "</u>: </td> <td class='subject'> " . $row["subject"]. " </td> </tr> <tr> <td></td> <td class='comment' colspan='2'> " . $row["comment"]. " </td> </tr> "; } } else { echo " <tr> <td> No Comments </td> <tr> "; } ?> </table> </td> Quote Link to comment https://forums.phpfreaks.com/topic/298809-styling-comment-section-from-database/#findComment-1524354 Share on other sites More sharing options...
PineSmokes Posted October 26, 2015 Author Share Posted October 26, 2015 By double post do you mean in my code or I actually posted to this site twice? I can't for the life of me find out how to find my second post it says I have 2 posts but no link on how to get there. I only had this one post in my favorites, also I though it would have emailed me when anyone replied guess I just needed to check myself hah. Thanks for the quick and helpful responses I've since made a somewhat decent login/signup section. I'm still working on my login process but I'll be sure to hop into the correct section if I need more help I ended up using the border-top and border-bottom with the tr and td. I also really liked the first post because all that escaping was super annoying but if I had to chose one the second person nailed it. Quote Link to comment https://forums.phpfreaks.com/topic/298809-styling-comment-section-from-database/#findComment-1524402 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.