Web Analytics Made Easy -
StatCounter Help me please, lol - CodingForum

Announcement

Collapse
No announcement yet.

Help me please, lol

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help me please, lol

    Any ideas how to get this working?



    PHP Code:
        <?php

        

            $sql 
    "SELECT * FROM adddb ORDER BY dateinput DESC LIMIT 0,20";

                
    $result mysql_query($sql$conn) or die(mysql_error());

                    while (
    $newArray mysql_fetch_array($result)) {                     

                        
    $id $newArray['id'];

                        
    $nameof $newArray['nameof'];

                        
    $why $newArray['why'];                    

                        
    $link "view.php?id";
                        
                        
    $totalcomments 0;
                                
    $query "SELECT * FROM comments WHERE adddbid = $id";
                                    
    $result mysql_query($query);
                                        while (
    $user mysql_fetch_assoc ($result)) {
                        
    $totalcomments++;
    }
                echo 
    "<a href='$link=$id'>$nameof</a> $totalcomments<br>";

            }

    ?>

  • #2
    maybe you could explain what your trying to do, and whats not working,
    and post an error message is any exists.

    -Ken

    Comment


    • #3
      not exactly clear on your data structure but try this:
      PHP Code:
      <?php
      $result 
      mysql_query('SELECT * FROM adddb ORDER BY dateinput DESC LIMIT 0, 20') or exit(mysql_error());
      while (
      $row mysql_fetch_assoc($result)) {$array[$row['id']] = $row;}

      $result mysql_query('SELECT adddbid, COUNT(*) AS count FROM comments GROUP BY adddbid') or exit(mysql_error());
      while (
      $row mysql_fetch_assoc($result)) {$array[$row['adddbid']]['count'] = $row['count'];}

      foreach (
      $array as $key => $value)
      {
          echo 
      '<a href="view.php?id=' $key '">' $value['nameof'] . '</a>' $value['count'] . '<br>';
      }
      ?>

      Comment


      • #4
        At the moment i have 2 tables on with the name of someone, and the 2nd table has commens about that someone. the page should display the names with how many comments that have had about that someone.

        Comment


        • #5
          from what i can tell, you are using the variable $result in both loops. as soon as you query the second time inside the loop, the $result in the outer loop gets fubar.

          Comment


          • #6
            Originally posted by simjay
            At the moment i have 2 tables on with the name of someone, and the 2nd table has commens about that someone. the page should display the names with how many comments that have had about that someone.
            that's exactly what my code example does. again, not sure about your exact data structure.

            Comment


            • #7
              thank you for your code, it sort of works. lol. how can i get it so if comment total = 0 it displays 0

              Comment


              • #8
                try this:
                PHP Code:
                $result mysql_query('SELECT * FROM adddb ORDER BY dateinput DESC LIMIT 0, 20') or exit(mysql_error());
                while (
                $row mysql_fetch_assoc($result))
                {
                    
                $row['count'] = 0;
                    
                $array[$row['id']] = $row;
                }

                $result mysql_query('SELECT adddbid, COUNT(*) AS count FROM comments GROUP BY adddbid') or exit(mysql_error());
                while (
                $row mysql_fetch_assoc($result)) {$array[$row['adddbid']]['count'] = $row['count'];}

                foreach (
                $array as $key => $value)
                {
                    echo 
                '<a href="view.php?id=' $key '">' $value['nameof'] . '</a>' $value['count'] . '<br>';

                Comment


                • #9
                  gettin there lol. This is what i am getting:

                  Paul Baber (Argos Fire Protection Services) 0
                  Pederasts0
                  James Nesbitt (Yellow Pages ADs) 0
                  gaynor weston0
                  internet boyfriends 1
                  fencing 1
                  my "friend" katherine 0
                  bla1
                  parents 1
                  xerox 1
                  P.E. Teachers 1
                  Suicide 2
                  Charlotte McKenna 0
                  ipswich Town 0
                  Student Haters 0
                  Denise Slag Outen 1
                  Men I find attractive 0
                  Ricky Gervais 0
                  italians in general 2
                  WHITE SOCKS 2
                  1
                  2
                  1
                  1
                  3
                  1
                  7
                  1
                  1
                  3

                  Many thnaks for you help
                  Last edited by simjay; Jul 29, 2005, 03:46 PM.

                  Comment


                  • #10
                    This is what i have now, it seems to work fine apart from it not displaying everything from the database. Any Ideas


                    PHP Code:
                    <?


                     $result 
                    mysql_query('SELECT * FROM adddb ORDER BY nameof') or exit(mysql_error());
                    while (
                    $row mysql_fetch_assoc($result))
                    {
                        
                    $row['count'] = 0;
                        
                    $array[$row['id']] = $row;
                    }

                    $result mysql_query('SELECT adddbid, COUNT(*) AS count FROM comments ') or exit(mysql_error());
                    while (
                    $row mysql_fetch_assoc($result)) {$array[$row['adddbid']]['count'] = $row['count'];}

                    foreach (
                    $array as $key => $value)
                    {

                        echo 
                    '<a href="view.php?id=' $key '">' $value['nameof'] . '</a> <font color="#FF0000">' $value['count'] . '<br>';
                       }    

                    ?>

                    Comment


                    • #11
                      simjay please read our posting guidelines before creating any more threads

                      http://www.codingforum.net/postguide.htm
                      Spookster
                      CodingForum Supreme Overlord
                      All Hail Spookster

                      Comment

                      Working...
                      X