Results 1 to 7 of 7

Thread: Comment Script Issues

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Comment Script Issues

    Hello, I am trying to make a script that will allow a user to comment once on a job done for them. I got it working fine to only allow them to leave one comment, but then I realized that on user may have multiple jobs to comment and that I need them to be able to comment once on each job. I have a page that shows is supposed to show the jobs available for commenting, but when I run the page, I get nothing. Here is the code:
    PHP Code:
    <?php

    // Get username
    $user $_SESSION['user'];

    // Query to get job data
    $sql "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
    $result mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
    $row mysql_fetch_array($result);
    // Get number of results
    $results mysql_num_rows($result);

    // If there are no results
    if($results 1) {
        echo 
    '
        There are no jobs availible for you to comment. Contact me <a href="http://echo-designes.com/contact.php">here</a> to have a job done.
        <br />
        '
    ;
    }

    // Find out whether to display "are" or "is" and "jobs" or "job"
    if($results 1) {
        
    $are "is";
        
    $job "job";
    }
    else {
        
    $are "are";
        
    $job "jobs";
    }
        
    // If there are results    and form is not active
    if($results >= && !$_GET['page']) {

    // Tell how many jobs can be commented
    echo '
    There '
    .$are.' <i>'.$results.'</i> '.$job.' that you may comment.
        <br /><br />
    '
    ;

        echo 
    'Chose the job you would like to comment.
        <br /><br />'
    ;

    // get job data
        
    $sql "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
        
    $jobs mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
        
    $j mysql_fetch_array($jobs);
        
    $title $j['title'];
    $comments mysql_query("SELECT * FROM `comments` WHERE job = '$title'") or die ('Error Checking Comments! <br />' .mysql_error());
    $c mysql_fetch_array($comments);


    // Display jobs
    while($job mysql_fetch_array($jobs)) {

            if(
    $job['title'] !== $c['title']) {
                echo 
    '
                <a href="comment.php?page=add&id='
    .$job['id'].'">'.$job['title'].'</a>
                    <br />'
    ;
            }
    }

    }


    // If add was hit
    if($_GET['page'] == "add") {
        require(
    'add.php');
    }

    ?>
    The pages reads that there is indeed a job to comment, but does not display the link to comment it (in the while statement). Thanks
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    if($results = 1) {
        $are = "is";
        $job = "job";
    }
    else {
        $are = "are";
        $job = "jobs";
    }
    One logical error in the above condition that must be == i think.

  3. #3
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    you are correct, = assigns values, == is equal, and === is exact match.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    I saw the same thing. Those equal signs get me all the time. Haha.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for pointing out the incorrect "=" usage, I appreciate it. However, the main issue is still unresolved because the page still does not display links to comment on jobs that currently have not been commented. Any ideas?
    Thanks DD, you saved me countless times

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Not 100% sure on this, but wouldn't this have something to do with it:

    Code:
    // get job data
        $sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
        $jobs = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
        $j = mysql_fetch_array($jobs);
        
    $title = $j['title'];
    $comments = mysql_query("SELECT * FROM `comments` WHERE job = '$title'") or die ('Error Checking Comments! <br />' .mysql_error());
    $c = mysql_fetch_array($comments);
    
    
    // Display jobs
    while($job = mysql_fetch_array($jobs)) {
    
            if($job['title'] !== $c['title']) {
                echo '
                <a href="comment.php?page=add&id='.$job['id'].'">'.$job['title'].'</a>
                    <br />';
            }
    }
    It seems to me that you are selecting jobs that are already commented on. That is why you are not getting any links to show up. Try removing the part in red in the above snippet.

    Hope this helps.

    Added Later:
    ---------------------------------------

    After looking at the original script a little more, if what I posted above doesn't work, try undoing that and removing the following part in red.

    Code:
    // get job data
        $sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
        $jobs = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
        $j = mysql_fetch_array($jobs);
        
    $title = $j['title'];
    $comments = mysql_query("SELECT * FROM `comments` WHERE job = '$title'") or die ('Error Checking Comments! <br />' .mysql_error());
    $c = mysql_fetch_array($comments);
    
    
    // Display jobs
    while($job = mysql_fetch_array($jobs)) {
    
            if($job['title'] !== $c['title']) {
                echo '
                <a href="comment.php?page=add&id='.$job['id'].'">'.$job['title'].'</a>
                    <br />';
            }
    }
    Last edited by thetestingsite; 03-02-2007 at 03:46 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help guys. I decided to redo it another way that I think will work better for what I want to do. So far I think its working fine
    Thanks DD, you saved me countless times

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
  •