count

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deccypher
    New Member
    • Mar 2008
    • 14

    count

    hi i got the count functon working but this it the first time i have ever used it
    [php]$_result = mysql_query(" SELECT COUNT( * ) FROM `table` WHERE `colum` = '$sid' ");
    echo "$_result Phones Supported"; [/php]
    i can tell my echo is wriong. but i dont know what i should be doing here

    Please enclose your posted code in [code] tags (See How to Ask a Question). Please use [code] tags in future.

    MODERATOR
    Last edited by ronverdonk; Mar 24 '08, 12:02 AM. Reason: code within code tags
  • DavidPr
    New Member
    • Mar 2007
    • 155

    #2
    You may try something like this:

    [PHP]$query = "SELECT COUNT(*) AS numrows FROM `table` WHERE colum = '$sid'";
    $result = mysql_query($qu ery);
    $row = mysql_fetch_arr ay($result, MYSQL_ASSOC);
    $numrows = $row['numrows'];
    }
    echo "$numrows Phones Supported";[/PHP]

    or

    [PHP]$query = "SELECT COUNT(*) FROM `table` WHERE colum = '$sid'";
    $result = mysql_query($qu ery);
    while($row = mysql_fetch_arr ay($result))
    {
    $number = $row['COUNT(*)'];
    }
    echo "$number Phones Supported"; [/PHP]

    Comment

    • Deccypher
      New Member
      • Mar 2008
      • 14

      #3
      Works great,

      thank you i just couldn't figure out how to show the results when the query itsself was the result and not generating variables.

      this is going in my bookmarks lol

      thanks again

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Or, if i understand your problem, you could use the mysql_num_rows( )'s function.

        [php]
        $_query = mysql_query(".. .");
        $_rows = mysql_num_rows( $_query);
        echo $_rows;
        [/php]

        Comment

        • Deccypher
          New Member
          • Mar 2008
          • 14

          #5
          Originally posted by markusn00b
          Or, if i understand your problem, you could use the mysql_num_rows( )'s function.

          [php]
          $_query = mysql_query(".. .");
          $_rows = mysql_num_rows( $_query);
          echo $_rows;
          [/php]
          this bit will solve the overall problem thanks

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by Deccypher
            this bit will solve the overall problem thanks
            Welcome!

            See you around.

            Markus.

            Comment

            Working...