SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot amit290's Avatar
    Join Date
    Oct 2001
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    count number records in mysql which has X value

    Hi,

    How could I count how many records in a MySQL table which has "yes" in one of the fields?

    Thanks in advance

  2. #2
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A way would be:
    PHP Code:
    $QueryCount mysql_query("SELECT COUNT(*) FROM Table WHERE SomeValue = 'yes'");
    $Count mysql_result($QueryCount0); 

  3. #3
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query "SELECT * FROM table WHERE somevalue = 'yes'";
    $result=mysql_query($query);
    $count=count(mysql_num_rows($result), 0);
    $counter=mysql_query($count);
    echo 
    "$counter"
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  4. #4
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did this work?
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  5. #5
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Saying that, you may not need count() and could just use mysql_num_rows.
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  6. #6
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you even have any clue what you are doing, 1337-Dev?

    If you wanted to do it using mysql_num_rows (I would actually suggest doing it jazztie's way), you would do it like this:

    PHP Code:
    $getrows mysql_query("SELECT * FROM `table` WHERE `this` = 'yes'") or die(mysql_error());
     
    $numrows mysql_num_rows($getrows);
     echo 
    $numrows


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
  •