SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing form code

    Hi,

    i have this code where a 1 or denotes whether to show a for to add comments or just show the comments with out the form, but it's constantly just showing the form, the comments and id's are getting stored in the database ok here is the code:

    PHP Code:
            // Check Comments 
            
    $query2 mysql_query("select * from `member_comments` where `mid`='$id2'") or die(mysql_error()); 
            
            
    $id2 $id
            
            
    $count_comments mysql_num_rows($query2); 
            
            
    $form '<form action="comment_post.php" method="POST"> 
            <textarea name="comments" cols="20" rows="2">
            </textarea>
            <br />
            <input type="hidden" name="mid" value="'
    .$id2.'">
            <input type="submit" value="Add Comment"> </form>'
    // check that the comment view area is needed. 
            
    if (!($count_comments=="0")) { 
            
    $show_com '1'
               } else {
            
    $show_com '0'
            } 
            
            
    // If yes show comments if no only show form. 
            
    if ($show_com == '1'
            { 
            while (
    $row2=mysql_fetch_array($query2)) { 
                    
            
    $id2_com $row2[id]; 
            
    $quick_name mysql_query("SELECT * FROM `membership` WHERE `id`='$row2[uid]' LIMIT 1") or die (mysql_error()); 
            
            while (
    $n=mysql_fetch_array($quick_name)){ 
            
    $mem_name $n["username"]; 
            } 
            echo 
    '<hr />';        
            echo 
    'Posted By: <a href="view_profile.php?id='.$row2[uid].'">'.$mem_name.'</a><br>'
            echo 
    'On: '.$row2[posted].'<br>'
            echo 
    'Comment: '.$row2[comments].'<br><br>'
            echo 
    '<hr />';            
            }         
            echo 
    $form
             } else {
            echo 
    $form

    cheers for any help

    Graham

  2. #2
    SitePoint Zealot Bill Palmer's Avatar
    Join Date
    Oct 2005
    Location
    London, UK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Be careful when using strings and literals in comparisons... you're probably safer using === and !===.

    Also, when outputting large blocks of HTML, do the following:

    PHP Code:
    <?php

    echo <<<EOF
    your html code here
    <em>some html</em>
    you can output 
    $variables too, use \ to escape $ if so desired (e.g. \$)
    EOF;

    ?>
    No need to mix and match ' and ", and no need to escape either of them. Also, there can't be any whitespace before the ending EOF.

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try changing
    PHP Code:
    if (!($count_comments=="0")) { 
    to
    PHP Code:
    if ($count_comments != "0"){ 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mate,

    tried what you said mandes, still the same, it stores the comments, and users id's perfectly in the database but it has trouble with the form, it just keeps showing it instead of echoing out the comments.

    cheers

    Graham

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I use a line in several sites that does the same the only difference is I use ' instead of " and check for positive logic instead of negative.

    PHP Code:
    if ($count_comments == '0')) { 
            echo 
    $form
    } else { 
            while (
    $row2=mysql_fetch_array($query2)) { 
     
            
    $id2_com $row2[id]; 
            
    $quick_name mysql_query("SELECT * FROM `membership` WHERE `id`='$row2[uid]' LIMIT 1") or die (mysql_error()); 
     
            while (
    $n=mysql_fetch_array($quick_name)){ 
            
    $mem_name $n["username"]; 
            } 
            echo 
    '<hr />';         
            echo 
    'Posted By: <a href="view_profile.php?id='.$row2[uid].'">'.$mem_name.'</a><br>'
            echo 
    'On: '.$row2[posted].'<br>'
            echo 
    'Comment: '.$row2[comments].'<br><br>'
            echo 
    '<hr />';             
            }          
            echo 
    $form
     } 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mate,

    Thanks for the code, i will do it the way you were saying in future, this code is doing my head in lol here is what i have now using your code:

    PHP Code:
            $id mysql_escape_string(trim($_GET['id'])); 
            if (empty(
    $id)) { die('Error, no profile selected'); } 
                    
            
    // Get Profile 
            
    $query "select * from `membership` where `id`='$id' limit 1"
            
    $result mysql_query($query) or die(mysql_error()); 
            
            if (
    mysql_num_rows($result)==1
            { 
            
            
            
    $row mysql_fetch_array($result); 
            
    extract($row); echo '<strong>Viewing '.$username.'īs Profile </strong>'
            echo 
    '<p>Email: '.$email.'<br> 
            Last Login: '
    .$login.'<br> 
            Joined: '
    .$join_date.'<br>.'
            if (
    $status=='N'
            { 
            echo 
    'Status: pending</p>'
            } 
            else 
            { echo 
    'Status: active</p>'; } 
            
            
            
    // Check Comments 
            
    $query2 mysql_query("select * from `member_comments` where `mid`='$id2'") or die(mysql_error());         
            
    $id2 $id;         
            
    $count_comments mysql_num_rows($query2); 
            
            
    $form '<form action="comment_post.php" method="POST">
                     <textarea name="comments" cols="20" rows="2">
                     </textarea> <input type="hidden" name="mid" value="'
    .$id2.'">
                     <input type="submit" value="Add Comment">
                     </form>'
    // check that the comment view area is needed. 
                     
            
    if ($count_comments != '0') { 
            
            echo 
    $form
            
            } else { 
            
            }
            while (
    $row2=mysql_fetch_array($query2)) { 

            
    $id2_com $row2[id]; 
            
    $quick_name mysql_query("SELECT * FROM `membership` WHERE `id`='$row2[uid]' LIMIT 1") or die (mysql_error()); 

            while (
    $n=mysql_fetch_array($quick_name)){ 
            
            
    $mem_name $n["username"]; 
            
            } 
            echo 
    '<hr />';         
            echo 
    'Posted By: <a href="view_profile.php?id='.$row2[uid].'">'.$mem_name.'</a><br>'
            echo 
    'On: '.$row2[posted].'<br>'
            echo 
    'Comment: '.$row2[comments].'<br><br>'
            echo 
    '<hr />';             
            }          
            echo 
    $form

    it still only shows up the textare and not the message, it'll be somethin really simple no doubt lol

    thank for the help mate

    Graham

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT:

    fixed it changed this line:

    $query2 = mysql_query("select * from `member_comments` where `mid`='$id'") or die(mysql_error());
    thanks for the input

    Graham

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well done, I was going to suggest echoing out the value of the mysql_num_rows next to see that you had something in there, but loks like youre sorted
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, thanks for all the help mate, i used the code you made above it looks a lot better

    cheers

    Graham


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •