MySql dumb question (maybe) :)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MichaelP
    Registered User
    • Aug 2003
    • 7124

    #1

    MySql dumb question (maybe) :)

    Is there a simple way to show how many entries from a database ?

    like " select * FROM thistable limit= total,1..." well you get the idea

    Thnaks in advance
  • egonetworks
    Confirmed User
    • Jan 2004
    • 6706

    #2
    How about using count?

    Comment

    • lilj
      Confirmed User
      • Dec 2003
      • 1536

      #3
      Originally posted by egonetworks
      How about using count?

      Does your network need a Reality Check? [ Find Out ]

      Comment

      • egonetworks
        Confirmed User
        • Jan 2004
        • 6706

        #4
        that's:

        select count(*) from table

        just incase you've never used it before

        Comment

        • cjnet
          Registered User
          • Mar 2004
          • 281

          #5
          not really i don't think..

          in php the easiest way would be:

          $query = "SELECT * FROM TABLE"
          $result = mysql_query($query) or die("Failed to Get Crap");
          $count = mysql_num_rows($result);

          i'm pretty sure.. if that helps =O

          Comment

          • MichaelP
            Registered User
            • Aug 2003
            • 7124

            #6
            Originally posted by cjnet
            not really i don't think..

            in php the easiest way would be:

            $query = "SELECT * FROM TABLE"
            $result = mysql_query($query) or die("Failed to Get Crap");
            $count = mysql_num_rows($result);

            i'm pretty sure.. if that helps =O
            Thank you but i tried it and it doesn,t work... Maybe if I can just show the highest ID from the db it would be ok too

            Comment

            • JSA Matt
              So Fucking Banned
              • Aug 2003
              • 5464

              #7
              Originally posted by egonetworks
              select count(*) from table
              if that's not the answer, we don't understand the question

              Comment

              • MichaelP
                Registered User
                • Aug 2003
                • 7124

                #8
                Originally posted by JSA Matt
                if that's not the answer, we don't understand the question
                Ho you REALLY WELL understood it, it is just that I tried this nad it didn,t work.. Sorry guy I am not very used with MySql queries yet

                include_once("sql_include.php"); /= this is where i connect to DB

                $sql = "SELECT count(*) FROM tblEntries";
                $result = SQL_Query($sql);

                echo $result ;

                I know I am not that far but not there yet

                Comment

                • JSA Matt
                  So Fucking Banned
                  • Aug 2003
                  • 5464

                  #9
                  Code:
                  $query = mysql_query("SELECT COUNT(*) FROM table")or die(mysql_error());
                      list($rows) = mysql_fetch_row($query);
                  
                  echo $rows;

                  Comment

                  • MichaelP
                    Registered User
                    • Aug 2003
                    • 7124

                    #10
                    Ok got it

                    include_once("sql_include.php");
                    $sql = "SELECT * FROM thistable ORDER BY id DESC LIMIT 0 , 1";
                    $result = SQL_Query($sql);
                    while($row = mysql_fetch_array($result["ResultSet"]))
                    {
                    print "" . $row["id"] . "" ;
                    }


                    Thanks to all for your help. it is very appreciated

                    Comment

                    • s9ann0
                      Confirmed User
                      • Sep 2001
                      • 4873

                      #11
                      whats wrong with

                      select count(*) from table

                      ?

                      Comment

                      • Ash@phpFX
                        Confirmed User
                        • Nov 2003
                        • 4292

                        #12
                        using count() is the most efficient way

                        Comment

                        • WombRaider
                          Confirmed User
                          • Sep 2002
                          • 159

                          #13
                          Here's another way that's worked for me:

                          $query = mysql_query("SELECT * FROM tableName");
                          $qty = mysql_num_rows($query);
                          echo $qty;

                          Hope that helps.
                          Fred, I think I fried the motherboard.........and the fatherboard, too.

                          Comment

                          Working...