Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    hello...

    i have problem in count function used in mysql.
    I have a table name alu_dir with following fields :

    PRIMARY KEY(id),
    Name VARCHAR(50),
    Batch VARCHAR(50),
    Organization VARCHAR(50),
    Designation VARCHAR(50),
    Address_local VARCHAR(100),
    Address_working VARCHAR(100),
    Contact_no VARCHAR(50),
    Email_id VARCHAR(50)

    its working and i am inserting values in it and can display the fields in webpage.

    now the problem is that batch field has three values . 1. Engg 2. prog 3. analyst

    what i want is to count total number of people who are in engg , prog and analyst ....and display them in seperate webpage ...this number should referesh automatically after inserting values in table alu_dir.

    i want only the number of people with diffrent batch to be displayed .

    pls help me out ...
    Anant

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well, on the page where you want to count the number of rows with the value "engg" just have your query as

    PHP Code:
    $query "SELECT * FROM alu_dir WHERE batch='engg'" 
    And then you will just do that but differently for 'prog' and 'analyst'

    Hope this helps.

  4. #3
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    Quote Originally Posted by bfsog
    Well, on the page where you want to count the number of rows with the value "engg" just have your query as

    PHP Code:
    $query "SELECT * FROM alu_dir WHERE batch='engg'" 
    And then you will just do that but differently for 'prog' and 'analyst'

    Hope this helps.

    Thanx for the concern ..but what u said will display all the fields and ..and with different id number ..and i wnat to count the number of student u had taken engg. so simple total is what i need...

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah, but then you would do something like:

    PHP Code:
            $query "SELECT * FROM alu_dir WHERE batch='engg'";
        
    $result mysql_query($query) or die("Query failed: ".mysql_error());
        
    $numrows mysql_num_rows($result);
            echo 
    "number of rows: $numrows"

  6. #5
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    That is extremely inefficient as the database has to fetch all the records.

    What they want is...
    Code:
    SELECT COUNT(*) FROM alu_dir WHERE batch='engg'
    Sean

  7. #6
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    Quote Originally Posted by seanmiller
    That is extremely inefficient as the database has to fetch all the records.

    What they want is...
    Code:
    SELECT COUNT(*) FROM alu_dir WHERE batch='engg'
    Sean
    Thanx for the reply and it worked ...


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:04 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com