#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Location
    Philippines
    Posts
    83
    Rep Power
    4

    [Help] How to Post Comments with Approval


    Hello there, I've been wondering how I can make a News System with Comments? That those comments need to be approved first by admin before directly posting it on the current news item? Can anyone give me ideas ( PHP and MYSQL structure or flow chart ) on how I will start making this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    381
    well you need a posts table, and comments table.. in comments table you need id, post_id, username, comment, is_approved

    then when you display posts, query for just the comments belonging to that post where is_approved = 1
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Location
    Philippines
    Posts
    83
    Rep Power
    4
    Originally Posted by paulh1983
    well you need a posts table, and comments table.. in comments table you need id, post_id, username, comment, is_approved

    then when you display posts, query for just the comments belonging to that post where is_approved = 1
    Im wondering how I will extract those comments (approved comments) to current news item using php
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    381
    using a query... :s if you have to ask then i think you need to do some basic training on php/mysql..
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Location
    Philippines
    Posts
    83
    Rep Power
    4
    Originally Posted by paulh1983
    using a query... :s if you have to ask then i think you need to do some basic training on php/mysql..
    I think you dont understand what Im pointing to sorry. So here's my current problem...

    Code..
    PHP Code:
    <?php
        
    require_once(' PATH TO MY SYSTEM SETTINGS ');

        
    $id    $core->clean$_GET['id'] );
    ?>
    <div class="right-news-page">
        <div class="news-comment-top"></div>
        <div class="news-comment">
            <div class="news-comment-item">
                <?php 
                    $query 
    $db->query"SELECT * FROM news_comments WHERE post_id = '{$id}' ORDER BY stamp DESC" );
                    
    $num   $db->num$query );
                                        
                            while( 
    $array $db->assoc$query ) ) {
                
    ?>
                <div class="news-comment-item-body">
                    <b><?php echo $array['habbo']; ?>: </b><?php echo $array['comment']; ?>
                </div>
                <?php
                
    }
                    if( 
    $num == ) {
                
    ?>
                <div class="news-comment-item-body">
                    No Comments
                </div>
                <?php ?>
            </div>
        </div>
    </div>
    <?php 

            $query 
    $db->query"SELECT * FROM news WHERE id = '{$id}'" );
            
    $array $db->assoc$query );
            
    $num   $db->num$query );
                    
        
    $query2 $db->query"SELECT * FROM users WHERE id = '{$array['author']}'" );
        
    $array2 $db->assoc$query2 );

        
    $query3 $db->query"SELECT * FROM news_categories WHERE id = '{$array['category']}'" );
        
    $array3 $db->assoc$query3 );

    ?>

            <div class="left-news-page">
                <div class="news-con">
                    <div class="news-top">
                            <img src="cdn/_images/FAN.gif" align="right">
                        <div class="ribbon">
                            <img src="http://www.habbo.com/habbo-imaging/avatarimage?hb=img&user=<?php echo $array2['habbo']; ?>&head_direction=2&action=wav&gesture=sml&headonly=1" align="middle" id="newsiee">
                        </div>
                        <div class="title">
                            <?php
                        
                                
    echo $num == $array['title'] : 'Oops!';
                                
                            
    ?>
                        </div>
                        <div class="author"><i>by <?php echo $array2['habbo']; ?></i></div>
                    </div>
                <?php

                    
    if( $num == ) {

                
    ?>
                    <div class="news-item-body">
                        <?php echo html_entity_decodenl2br$array['article'] ) ); ?>
                        <div id="clear"></div>
                        <div class="divider"></div>
                    </div>
                    <div id="clear"></div>
                </div>
                <div id="clear"></div>
                <div class="container">
                    <div class="container-body">
                        <div id="form-messages"></div>
                            <h3 class="comment-h2">Post a comment</h3>
                            <div class="divider"></div>
                        <form id="ajax-contact" method="post" action="cdn/_pages/postComment.php">
                            <input type="text" name="habbo" id="habbo" placeholder="Your Habbo Name..." required>
                            <textarea name="message" id="message" style="width:93%;" placeholder="Your Comment..." required></textarea>
                            <input type="hidden" name="newsid" value="<?php echo $array['id']; ?>"><br />
                            <input type="submit" name="submit" value="Post!" style="float:right" class="comment-submit" />
                        </form>
                    </div>
                </div>
            </div>
            <script data-cfasync="false" type="text/javascript" src="cdn/_js/comments.js"></script>

                            <?php
                                
    }
                            else {
                                
    ?>
            <div class="left-news-page">
                <div class="container">
                    <div class="container-body">
                        Ooppss! No News!
                    </div>
                </div>
            </div>
                            <?php
                                
    }
                            
    ?>
    I used
    PHP Code:
    post_id '{$id}' 
    so it will show comments that are on current news ( news.php?id=19, page must show comments that has post_id = 19 ) . But its not working.

    SCREENSHOTS.


  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Posts
    2,233
    Rep Power
    1297
    What does "its not working" mean?



    Start by changing:
    PHP Code:
    post_id '{$id}' 
    To:
    PHP Code:
    post_id '$id' 

    Comments on this post

    • Will-O-The-Wisp agrees : Thanks for helping out here!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Location
    Philippines
    Posts
    83
    Rep Power
    4
    Originally Posted by FishMonger
    What does "its not working" mean?



    Start by changing:
    PHP Code:
    post_id '{$id}' 
    To:
    PHP Code:
    post_id '$id' 
    I mean the Comments are not showing. I changed it already but nothing happens.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Location
    Philippines
    Posts
    83
    Rep Power
    4
    UPDATE : Issue solved. First I'm using a hashbang/hashchange on my site thats why when I try to echo the current ID of the news it shows "19.php" so I tried to make it
    PHP Code:

    $currentID 
    = (int)$id 

    $query 
    $db->query"SELECT * FROM news_comments WHERE post_id = '$currentID' ORDER BY stamp DESC" ); 
    and it works. Thank you guys

    Comments on this post

    • Will-O-The-Wisp agrees : Great! Glad to hear this is solved - I'll close this for now. PM me if you need the thread re-opened!

IMN logo majestic logo threadwatch logo seochat tools logo